Java.lang.Boolean.equals() 方法
描述
java.lang.Boolean.equals(Object obj) 当且仅当参数不为 null 并且是表示与此对象相同的布尔值的布尔对象时才返回 true。
声明
以下是 java.lang.Boolean.equals() 方法的声明。
public boolean equals(Object obj)
覆盖
等于类对象
参数
obj − 比较对象
返回值
如果布尔对象表示相同的值,则此方法返回 true,否则返回 false。
异常
NA
示例
下面的例子展示了 lang.Boolean.equals() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class BooleanDemo {
public static void main(String[] args) {
// create 2 Boolean objects b1, b2
Boolean b1, b2;
// create a boolean primitive res
boolean res;
// assign values to b1, b2
b1 = new Boolean(true);
b2 = new Boolean(false);
// assign the result of equals method on b1, b2 to res
res = b1.equals(b2);
String str = "b1:" +b1+ " and b2:" +b2+ " are equal is " + res;
// print res value
System.out.println( str );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
b1:true and b2:false are equal is false

