From 0930c78ff7bc270b13276c254e5ba9ac4494a875 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Tue, 25 Oct 2016 21:13:32 +0530 Subject: [PATCH] BAEL-29-String Conversion changes --- .../java/conversion/StringConversion.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java diff --git a/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java b/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java new file mode 100644 index 0000000000..c83ea6a20c --- /dev/null +++ b/core-java/src/main/java/com/baeldung/java/conversion/StringConversion.java @@ -0,0 +1,60 @@ +package com.baeldung.java.conversion; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalTime; +import java.util.Date; + +import com.baeldung.datetime.UseLocalTime; + +public class StringConversion { + + public static int getInt(String str) { + return Integer.parseInt(str); + } + + public static int getInteger(String str) { + return Integer.valueOf(str); + } + + public static long getLongPrimitive(String str) { + return Long.parseLong(str); + } + + public static Long getLong(String str) { + return Long.valueOf(str); + } + + public static double getDouble(String str) { + return Double.parseDouble(str); + } + + public static double getDoublePrimitive(String str) { + return Double.valueOf(str); + } + + public static byte[] getByteArray(String str) { + return str.getBytes(); + } + + public static char[] getCharArray(String str) { + return str.toCharArray(); + } + + public static boolean getBooleanPrimitive(String str) { + return Boolean.parseBoolean(str); + } + + public static boolean getBoolean(String str) { + return Boolean.valueOf(str); + } + + public static Date getJava6Date(String str, String format) throws ParseException { + SimpleDateFormat formatter = new SimpleDateFormat(format); + return formatter.parse(str); + } + + public static LocalTime getJava8Date(String str) throws ParseException { + return new UseLocalTime().getLocalTimeUsingParseMethod(str); + } +}