Package java.lang
Class Boolean
- java.lang.Object
-
- java.lang.Boolean
-
- All Implemented Interfaces:
Serializable
,Comparable<Boolean>
,Modified
public final class Boolean extends Object implements Serializable, Comparable<Boolean>, Modified
The wrapper for the primitive typeboolean
.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
booleanValue()
Gets the primitive value of this boolean, eithertrue
orfalse
.static int
compare(boolean lhs, boolean rhs)
Compares twoboolean
values.int
compareTo(Boolean that)
Compares this object to the specified boolean object to determine their relative order.boolean
equals(Object o)
Compares this instance with the specified object and indicates if they are equal.int
hashCode()
Returns an integer hash code for this boolean.static boolean
parseBoolean(String s)
Parses the specified string as aboolean
.String
toString()
Returns a string containing a concise, human-readable description of this boolean.static String
toString(boolean value)
Converts the specified boolean to its string representation.static Boolean
valueOf(boolean b)
Returns aBoolean
instance for the specified boolean value.static Boolean
valueOf(String string)
Parses the specified string as a boolean value.
-
-
-
Constructor Detail
-
Boolean
public Boolean(String string)
Constructs a newBoolean
with its boolean value specified bystring
. Ifstring
is notnull
and 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 newBoolean
with the specified primitive boolean value.- Parameters:
value
- the primitive boolean value,true
orfalse
.
-
-
Method Detail
-
booleanValue
public boolean booleanValue()
Gets the primitive value of this boolean, eithertrue
orfalse
.- Returns:
- this object's primitive value,
true
orfalse
.
-
equals
public boolean equals(Object o)
Compares this instance with the specified object and indicates if they are equal. In order to be equal,o
must be an instance ofBoolean
and have the same boolean value as this object.- Overrides:
equals
in classObject
- Parameters:
o
- the object to compare this boolean with.- Returns:
true
if the specified object is equal to thisBoolean
;false
otherwise.- See Also:
Object.hashCode()
-
compareTo
public int compareTo(Boolean that)
Compares this object to the specified boolean object to determine their relative order.- Specified by:
compareTo
in interfaceComparable<Boolean>
- Parameters:
that
- the boolean object to compare this object to.- Returns:
- 0 if the value of this boolean and the value of
that
are equal; a positive value if the value of this boolean istrue
and the value ofthat
isfalse
; a negative value if the value if this boolean isfalse
and the value ofthat
istrue
. - Since:
- 1.5
- See Also:
Comparable
-
compare
public static int compare(boolean lhs, boolean rhs)
Compares twoboolean
values.- Parameters:
lhs
- First value.rhs
- Second value.- 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:
hashCode
in classObject
- Returns:
- this boolean's hash code, which is
1231
fortrue
values and1237
forfalse
values. - See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
Returns a string containing a concise, human-readable description of this boolean.
-
parseBoolean
public static boolean parseBoolean(String s)
Parses the specified string as aboolean
.- Parameters:
s
- the string representation of a boolean value.- Returns:
true
ifs
is notnull
and is equal to"true"
using case insensitive comparison,false
otherwise.- Since:
- 1.5
-
toString
public static String toString(boolean value)
Converts the specified boolean to its string representation.- Parameters:
value
- the boolean to convert.- Returns:
- "true" if
value
istrue
, "false" otherwise.
-
valueOf
public static Boolean valueOf(String string)
Parses the specified string as a boolean value.- Parameters:
string
- the string representation of a boolean value.- Returns:
Boolean.TRUE
ifstring
is equal to "true" using case insensitive comparison,Boolean.FALSE
otherwise.- See Also:
parseBoolean(String)
-
valueOf
public static Boolean valueOf(boolean b)
Returns aBoolean
instance for the specified boolean value.If it is not necessary to get a new
Boolean
instance, 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.TRUE
ifb
is equal totrue
,Boolean.FALSE
otherwise.
-
-