Package java.lang
Class Boolean
java.lang.Object
java.lang.Boolean
- All Implemented Interfaces:
Serializable,Comparable<Boolean>
public final class Boolean extends Object implements Serializable, Comparable<Boolean>
The wrapper for the primitive type
boolean.- Since:
- 1.0
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description booleanbooleanValue()Gets the primitive value of this boolean, eithertrueorfalse.static intcompare(boolean lhs, boolean rhs)Compares twobooleanvalues.intcompareTo(Boolean that)Compares this object to the specified boolean object to determine their relative order.booleanequals(Object o)Compares this instance with the specified object and indicates if they are equal.static booleangetBoolean(String string)Returns thebooleanvalue of the system property identified bystring.inthashCode()Returns an integer hash code for this boolean.static booleanparseBoolean(String s)Parses the specified string as aboolean.StringtoString()Returns a string containing a concise, human-readable description of this boolean.static StringtoString(boolean value)Converts the specified boolean to its string representation.static BooleanvalueOf(boolean b)Returns aBooleaninstance for the specified boolean value.static BooleanvalueOf(String string)Parses the specified string as a boolean value.
-
Field Details
-
TYPE
TheClassobject that represents the primitive typeboolean. -
TRUE
TheBooleanobject that represents the primitive valuetrue. -
FALSE
TheBooleanobject that represents the primitive valuefalse.
-
-
Constructor Details
-
Boolean
Constructs a newBooleanwith its boolean value specified bystring. Ifstringis notnulland is equal to "true" using a non-case sensitive comparison, the result will be a Boolean representing the primitive valuetrue, otherwise it will be a Boolean representing the primitive valuefalse.- Parameters:
string- the string representing a boolean value.
-
Boolean
public Boolean(boolean value)Constructs a newBooleanwith the specified primitive boolean value.- Parameters:
value- the primitive boolean value,trueorfalse.
-
-
Method Details
-
booleanValue
public boolean booleanValue()Gets the primitive value of this boolean, eithertrueorfalse.- Returns:
- this object's primitive value,
trueorfalse.
-
equals
Compares this instance with the specified object and indicates if they are equal. In order to be equal,omust be an instance ofBooleanand have the same boolean value as this object.- Overrides:
equalsin classObject- Parameters:
o- the object to compare this boolean with.- Returns:
trueif the specified object is equal to thisBoolean;falseotherwise.- See Also:
Object.hashCode()
-
compareTo
Compares this object to the specified boolean object to determine their relative order.- Specified by:
compareToin interfaceComparable<Boolean>- Parameters:
that- the boolean object to compare this object to.- Returns:
- 0 if the value of this boolean and the value of
thatare equal; a positive value if the value of this boolean istrueand the value ofthatisfalse; a negative value if the value if this boolean isfalseand the value ofthatistrue. - Since:
- 1.5
- See Also:
Comparable
-
compare
public static int compare(boolean lhs, boolean rhs)Compares twobooleanvalues.- Returns:
- 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs. (Where true > false.)
- Since:
- 1.7
-
hashCode
public int hashCode()Returns an integer hash code for this boolean.- Overrides:
hashCodein classObject- Returns:
- this boolean's hash code, which is
1231fortruevalues and1237forfalsevalues. - See Also:
Object.equals(java.lang.Object)
-
toString
Returns a string containing a concise, human-readable description of this boolean. -
getBoolean
Returns thebooleanvalue of the system property identified bystring.- Parameters:
string- the name of the requested system property.- Returns:
trueif the system property named bystringexists and it is equal to "true" using case insensitive comparison,falseotherwise.- See Also:
System.getProperty(String)
-
parseBoolean
Parses the specified string as aboolean.- Parameters:
s- the string representation of a boolean value.- Returns:
trueifsis notnulland is equal to"true"using case insensitive comparison,falseotherwise.- Since:
- 1.5
-
toString
Converts the specified boolean to its string representation.- Parameters:
value- the boolean to convert.- Returns:
- "true" if
valueistrue, "false" otherwise.
-
valueOf
Parses the specified string as a boolean value.- Parameters:
string- the string representation of a boolean value.- Returns:
Boolean.TRUEifstringis equal to "true" using case insensitive comparison,Boolean.FALSEotherwise.- See Also:
parseBoolean(String)
-
valueOf
Returns aBooleaninstance for the specified boolean value.If it is not necessary to get a new
Booleaninstance, it is recommended to use this method instead of the constructor, since it returns its static instances, which results in better performance.- Parameters:
b- the boolean to convert to aBoolean.- Returns:
Boolean.TRUEifbis equal totrue,Boolean.FALSEotherwise.
-