BAEL-29-String Conversion changes

This commit is contained in:
Nikhil Khatwani 2016-10-25 21:13:32 +05:30
parent 54572b9c9d
commit 0930c78ff7
1 changed files with 60 additions and 0 deletions

View File

@ -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);
}
}