the java.lang.boolean class is a final class and it is a subclass of object class. the boolean class wraps the value of primitive datatype boolean into a boolean object. an object of type boolean contains a single field whose type is boolean. in other words, the wrapper classes create objects for primitive data types. this class provides many methods for converting a boolean to a string and a string to a boolean as well as other constants and methods useful when dealing with a boolean.
syntaxpublic final class boolean extends object implements serializable, comparable
example1public class booleantest { public static void main(string[] args) { boolean b; b = new boolean(true); boolean b1; b1 = b.booleanvalue(); string data = "the primitive value of boolean object " + b + " is " + b1; system.out.println(data); }}
outputthe primitive value of boolean object true is true
example2 的中文翻译为:示例2public class booleantest1 { public static void main(string args[]) { boolean b1, b2; b1 = new boolean(true); b2 = new boolean("false"); system.out.println("b1 value is : "+ b1.booleanvalue()); system.out.println("b2 value is : "+ b2.booleanvalue()); system.out.println("b1 compareto b2 : "+ b1.compareto(b2)); system.out.println("b1 equals b2 : "+ b1.equals(b2)); }}
outputb1 value is : trueb2 value is : falseb1 compareto b2 : 1b1 equals b2 : false
以上就是boolean类在java中的重要性是什么?的详细内容。