0

Class Output { Public static void main ( String args[]) { String str= "true false true"; boolean x= Boolean.valueOf(str); System.out.print(x); } }

What is the output of this program..?

25th Feb 2017, 9:09 PM
bhargav
5 Antworten
+ 5
false - because str doesn't contain a boolean value. It will always output false, except for str="true";
25th Feb 2017, 9:17 PM
Tashi N
Tashi N - avatar
+ 5
Ok ^^ This is a typecast from String to Boolean. The Boolean to which was casted is true if the string is not null and is equal to the string "true" (ignoring case, so e.g "TRUE" or "tRue" is also true). Every other value stored to the string will be a Boolean representing false value after typecast.
25th Feb 2017, 9:41 PM
Tashi N
Tashi N - avatar
+ 1
Okay..thank you for your time..
25th Feb 2017, 9:50 PM
bhargav
0
Can u explain little bit more..?
25th Feb 2017, 9:32 PM
bhargav
0
boolean and strings are two different types of variables. the program you gave as an example makes as much sence as "what does the number red smell like?"
26th Feb 2017, 4:27 AM
oddeofreq
oddeofreq - avatar