Java tutorial
//package com.java2s; public class Main { public static boolean toBoolean(Object srcStr, boolean defaultValue) { try { if (srcStr != null) { return Boolean.parseBoolean(trim1(srcStr.toString())); } } catch (Exception e) { ; } return defaultValue; } public static String trim1(String str) { if (null == str) { return ""; } return str.trim(); } public static String toString(Object obj) { if (null == obj) { return ""; } return obj.toString(); } public static String toString(Object obj, String defaultStr) { if (null == obj) { return defaultStr; } return obj.toString(); } }