We Don't know JAVA #EP7
Wrapper Class Boolean

Photo by Andrew Neel on Unsplash

We Don't know JAVA #EP7 Wrapper Class Boolean

Guess The Answer First

class Main{
    public static void main(String ... args){
        Boolean b1= new Boolean("false");
        Boolean b2= new Boolean("#EP7");
        System.out.println(b1.equals(b2));
    }
}

Options

1. true

2. false

3. Compile Time Error

4. IllegalArgumentException

Answer: true

If you got it wrong let's fix that.

Wrapper class Boolean constructor work very different. It will only return true if you provide these types of argument: "true", "TRUE", "True" , "TrUE", "tRUe" etc. all these combinations will return true every thing else will be false.

Example:

class Main{
    public static void main(String ... args){
        Boolean b1= new Boolean("true");
        Boolean b2= new Boolean("True");
        Boolean b3= new Boolean("TRUE");
        Boolean b4= new Boolean("TrUe");
        Boolean b5= new Boolean("tRUe");
        System.out.println(b1+" "+b2+" "+b3+" "+b4+" "+b5);
    }
}

Output: true true true true true

Everything else will be false

Conclusion:

Boolean b1= new Boolean("false"); //b1=false

Boolean b2= new Boolean("#EP7"); //b2=false

System.out.println(b1.equals(b2)); //true