Java - Write code to Parse string to Bool

Requirements

Write code to Parse string to Bool

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String source = "book2s.com";
        boolean def = true;
        System.out.println(ParseBool(source, def));
    }//from www  . j av  a  2s.  co  m

    public static boolean ParseBool(String source, boolean def) {
        try {
            return Boolean.parseBoolean(source);
        } catch (NullPointerException e) {
            return def;
        }
    }
}