Here you can find the source of toBoolean(String value, boolean defaultValue)
public static Boolean toBoolean(String value, boolean defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { public static Boolean toBoolean(String value, boolean defaultValue) { if (isEmpty(value)) return defaultValue; try {/*from w ww .j a v a2s .co m*/ return Boolean.parseBoolean(value); } catch (Exception e) { return defaultValue; } } public static Boolean toBoolean(String value) { return toBoolean(value, false); } public static boolean isEmpty(String str) { if (str == null) return true; if ("".equals(str.trim())) return true; return false; } }