Java Reference
In-Depth Information
Boolean(boolean value) initializes the Boolean object to value .
Boolean(String s) converts s 'stexttoatrueorfalsevalueandstoresthis
value in the Boolean object.
The second constructor compares s 's value with true . Because the comparison is
case-insensitive, any uppercase/lowercase combination of these four letters (such as
true , TRUE , or tRue ) results in true being stored in the object. Otherwise, the con-
structor stores false in the object.
Note Boolean 's constructors are complemented by boolean
booleanValue() , which returns the wrapped Boolean value.
Boolean also declares or overrides the following methods:
int compareTo(Boolean b) compares the current Boolean object
with b todeterminetheirrelativeorder.Themethodreturns0whenthecurrent
objectcontainsthesameBooleanvalueas b ,apositivevaluewhenthecurrent
objectcontainstrueand b containsfalse,andanegativevaluewhenthecurrent
object contains false and b contains true.
boolean equals(Object o) compares the current Boolean object
with o andreturnstruewhen o isnotnull, o isoftype Boolean ,andbothob-
jects contain the same Boolean value.
static boolean getBoolean(String name) returns true when a
systemproperty(discussedlaterinthischapter)identifiedby name existsand
is equal to true.
int hashCode() returnsasuitablehashcodethatallows Boolean objects
to be used with hash-based collections (discussed in Chapter 5 ).
static boolean parseBoolean(String s) parses s , returning
trueif s equals "true" , "TRUE" , "True" ,oranyotheruppercase/lowercase
combination.Otherwise,thismethodreturnsfalse.( Parsing breaksasequence
of characters into meaningful components, known as tokens .)
String toString() returns "true" whenthecurrent Boolean instance
contains true; otherwise, this method returns "false" .
static String toString(boolean b) returns "true" when b con-
tains true; otherwise, this method returns "false" .
static Boolean valueOf(boolean b) returns TRUE when b con-
tains true or FALSE when b contains false.
Search WWH ::

Custom Search