class C
{
public static void main(
String[] args)
{
Boolean b1 = Boolean.valueOf(true);//line 1
Boolean b2 = Boolean.valueOf(true);//line 2
Boolean b3 = Boolean.valueOf("TrUe");
Boolean b4 = Boolean.valueOf("tRuE");
System.out.print((b1==b2) + ",");
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");
System.out.println(b3.equals(b4));
Boolean f= new Boolean("TRUE");
Boolean h =new Boolean("true");
System.out.println(f.equals(h));//line 3
String s = new String("true");
String s1= new String("TRUE");
System.out.println(s.equals(s1));//line 4
}
}
output of this program is
true true true
true
flase
My question is how line 1 and line 2 are correct.
The valueOf() takes string as an argument.The line 1 and line 2 is not taking string as an argument so it should throw NumberFormatException.
Why this is not happening.
Then coming to line 3.I though the equals() is case-sensitive but it is not true in line 3 but it is true in line 4.
Can anybody clear all my doubts.
Thanks in advance.