Java - Write code to convert 0 and 1 to Boolean

Requirements

Write code to convert 0 and 1 to Boolean

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "0";
        System.out.println(toBoolean(s));
    }//from w  w w . j a  va  2s  .  c om

    public static boolean toBoolean(String s) {
        if (s == null || s.length() == 0) {
            return false;
        }
        if (s.equals("0")) {
            return false;
        } else if (s.equals("1")) {
            return true;
        }
        return Boolean.parseBoolean(s);
    }
}