public final class Boolean
extends Object implements Serializable, Comparable<Boolean>
| java.lang.Object | |
| java.lang.Boolean | |
布尔类将原始类型boolean的值包装在对象中。 类型为Boolean的对象包含一个类型为boolean字段。
此外,该类提供了许多方法将 boolean转换为 String和 String转换为 boolean ,以及处理 boolean时有用的其他常量和方法。
Fields |
|
|---|---|
public static final Boolean |
FALSE 对应于原始值 |
public static final Boolean |
TRUE 对应于原始值 |
public static final Class<Boolean> |
TYPE 表示基本类型布尔值的Class对象。 |
Public constructors |
|
|---|---|
Boolean(boolean value) 分配代表 |
|
Boolean(String s) 分配 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
booleanValue() 以布尔 |
static int |
compare(boolean x, boolean y) 比较两个 |
int |
compareTo(Boolean b) 将这个 |
boolean |
equals(Object obj) 返回 |
static boolean |
getBoolean(String name) 返回 |
int |
hashCode() 返回此 |
static int |
hashCode(boolean value) 返回 |
static boolean |
logicalAnd(boolean a, boolean b) 返回将逻辑AND运算符应用于指定的 |
static boolean |
logicalOr(boolean a, boolean b) 返回将逻辑OR运算符应用于指定的 |
static boolean |
logicalXor(boolean a, boolean b) 返回将逻辑异或运算符应用于指定的 |
static boolean |
parseBoolean(String s) 将字符串参数解析为布尔值。 |
String |
toString() 返回表示此布尔值的 |
static String |
toString(boolean b) 返回表示指定布尔值的 |
static Boolean |
valueOf(String s) 用指定字符串表示的值返回 |
static Boolean |
valueOf(boolean b) 返回表示指定的 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.lang.Comparable
|
|
Boolean (boolean value)
分配代表 value参数的 Boolean对象。
注意:使用此构造函数很少合适。 除非需要新实例,否则静态工厂valueOf(boolean)通常是更好的选择。 它可能会产生更好的空间和时间表现。
| 参数(Parameters) | |
|---|---|
value |
boolean: the value of the Boolean. |
Boolean (String s)
如果字符串参数不是null ,则分配代表值true的Boolean对象,并且忽略大小写等于字符串"true" 。 否则,分配代表值false的Boolean对象。 例子:
new Boolean("True")产生代表true的Boolean对象。
new Boolean("yes")会生成代表false的Boolean对象。
| 参数(Parameters) | |
|---|---|
s |
String: the string to be converted to a Boolean. |
boolean booleanValue ()
以布尔 Boolean返回此 Boolean对象的值。
| 返回(Returns) | |
|---|---|
boolean |
the primitive boolean value of this object. |
int compare (boolean x,
boolean y)
比较两个boolean值。 返回的值与以下内容返回的值相同:
Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
| 参数(Parameters) | |
|---|---|
x |
boolean: the first boolean to compare |
y |
boolean: the second boolean to compare |
| 返回(Returns) | |
|---|---|
int |
the value 0 if x == y; a value less than 0 if !x && y; and a value greater than 0 if x && !y |
int compareTo (Boolean b)
比较此 Boolean另一个实例。
| 参数(Parameters) | |
|---|---|
b |
Boolean: the Boolean instance to be compared |
| 返回(Returns) | |
|---|---|
int |
zero if this object represents the same boolean value as the argument; a positive value if this object represents true and the argument represents false; and a negative value if this object represents false and the argument represents true |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if the argument is null |
也可以看看:
boolean equals (Object obj)
返回 true当且仅当参数不是 null并且是与 Boolean对象表示相同 boolean值的 boolean对象。
| 参数(Parameters) | |
|---|---|
obj |
Object: the object to compare with. |
| 返回(Returns) | |
|---|---|
boolean |
true if the Boolean objects represent the same value; false otherwise. |
boolean getBoolean (String name)
返回true当且仅当存在由参数命名的系统属性和等于字符串"true" 。 (从Java TM平台的1.0.2版开始,此字符串的测试不区分大小写。)系统属性可通过getProperty访问, getProperty由System类定义。
如果没有指定名称的属性,或者指定的名称为空或空值,则返回 false 。
| 参数(Parameters) | |
|---|---|
name |
String: the system property name. |
| 返回(Returns) | |
|---|---|
boolean |
the boolean value of the system property. |
int hashCode ()
返回此 Boolean对象的哈希码。
| 返回(Returns) | |
|---|---|
int |
the integer 1231 if this object represents true; returns the integer 1237 if this object represents false. |
int hashCode (boolean value)
返回boolean值的散列码; 与Boolean.hashCode()兼容。
| 参数(Parameters) | |
|---|---|
value |
boolean: the value to hash |
| 返回(Returns) | |
|---|---|
int |
a hash code value for a boolean value. |
boolean logicalAnd (boolean a,
boolean b)
返回将逻辑AND运算符应用于指定的 boolean操作数的结果。
| 参数(Parameters) | |
|---|---|
a |
boolean: the first operand |
b |
boolean: the second operand |
| 返回(Returns) | |
|---|---|
boolean |
the logical AND of a and b |
也可以看看:
boolean logicalOr (boolean a,
boolean b)
返回将逻辑OR运算符应用于指定的 boolean操作数的结果。
| 参数(Parameters) | |
|---|---|
a |
boolean: the first operand |
b |
boolean: the second operand |
| 返回(Returns) | |
|---|---|
boolean |
the logical OR of a and b |
也可以看看:
boolean logicalXor (boolean a,
boolean b)
返回将逻辑异或运算符应用于指定的 boolean操作数的结果。
| 参数(Parameters) | |
|---|---|
a |
boolean: the first operand |
b |
boolean: the second operand |
| 返回(Returns) | |
|---|---|
boolean |
the logical XOR of a and b |
也可以看看:
boolean parseBoolean (String s)
将字符串参数解析为布尔值。 如果字符串参数不是null ,则返回的boolean表示值true ,并且忽略大小写等于字符串"true" 。
例如: Boolean.parseBoolean("True")返回true 。
例如: Boolean.parseBoolean("yes")返回false 。
| 参数(Parameters) | |
|---|---|
s |
String: the String containing the boolean representation to be parsed |
| 返回(Returns) | |
|---|---|
boolean |
the boolean represented by the string argument |
String toString ()
返回表示此布尔值的String对象。 如果此对象表示值true ,则返回一个等于"true"的字符串。 否则,返回一个等于"false"的字符串。
| 返回(Returns) | |
|---|---|
String |
a string representation of this object. |
String toString (boolean b)
返回表示指定布尔值的String对象。 如果指定的Boolean是true ,那么字符串"true"将被退回,否则该字符串"false"将被退回。
| 参数(Parameters) | |
|---|---|
b |
boolean: the boolean to be converted |
| 返回(Returns) | |
|---|---|
String |
the string representation of the specified boolean |
Boolean valueOf (String s)
用指定字符串表示的值返回Boolean 。 如果字符串参数不是null并且与字符串"true"相等(忽略大小写),则返回的Boolean表示真值。
| 参数(Parameters) | |
|---|---|
s |
String: a string. |
| 返回(Returns) | |
|---|---|
Boolean |
the Boolean value represented by the string. |
Boolean valueOf (boolean b)
返回表示指定的boolean值的Boolean实例。 如果指定的boolean值为true ,则此方法返回Boolean.TRUE ; 如果是false ,则此方法返回Boolean.FALSE 。 如果不需要新的Boolean实例,通常应该优先使用此方法,而不是构造函数Boolean(boolean) ,因为此方法可能会产生显着更好的空间和时间性能。
| 参数(Parameters) | |
|---|---|
b |
boolean: a boolean value. |
| 返回(Returns) | |
|---|---|
Boolean |
a Boolean instance representing b. |