Java java.lang Boolean parseBoolean(String s)
Description Of Boolean: parseBoolean(String s)
The java.lang.Boolean.parseBoolean(String s) parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
Boolean.parseBoolean(String s) method returns the boolean represented by the string argument.
Code Example Java Boolean
public class BooleanExam {
public static void main(String[] args) {
// create and assign values to String's s1, s2
String s1 = "TRue";
String s2 = "yes";
// create 2 boolean primitives bool1, bool2
boolean bool1, bool2;
bool1 = Boolean.parseBoolean(s1);
bool2 = Boolean.parseBoolean(s2);
String str1 = "Parse boolean on " + s1 + " gives " + bool1;
String str2 = "Parse boolean on " + s2 + " gives " + bool2;
// print b1, b2 values
System.out.println(str1);
System.out.println(str2);
}
}
ไม่มีความคิดเห็น :
แสดงความคิดเห็น