Java tutorial
//package com.java2s; public class Main { public static boolean parse(String str, boolean fallback) { if (str == null) { return fallback; } return Boolean.parseBoolean(str); } public static byte parse(String str, byte fallback) { try { return Byte.parseByte(str); } catch (NumberFormatException e) { return fallback; } } public static short parse(String str, short fallback) { try { return Short.parseShort(str); } catch (NumberFormatException e) { return fallback; } } public static int parse(String str, int fallback) { try { return Integer.parseInt(str); } catch (NumberFormatException e) { return fallback; } } public static long parse(String str, long fallback) { try { return Long.parseLong(str); } catch (NumberFormatException e) { return fallback; } } public static float parse(String str, float fallback) { try { return Float.parseFloat(str); } catch (NumberFormatException e) { return fallback; } } public static double parse(String str, double fallback) { try { return Double.parseDouble(str); } catch (NumberFormatException e) { return fallback; } } public static char parse(String str, char fallback) { if (str == null || str.isEmpty()) { return fallback; } return str.charAt(0); } }