java包装类equals
字符类的equals()方法 (Character class equals() method)
equals() method is available in java.lang package.
equals()方法在java.lang包中可用。
equals() method is used to check equality or inequality of this Subset Object against the given Subset Object or in other words we can say this method is used to compare two Subset objects.
equals()方法用于检查此子集对象与给定子集对象的相等性或不相等性,换句话说,我们可以说此方法用于比较两个子集对象。
equals() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
equals()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
equals() method is a final method it does not override in child class.
equals()方法是最终方法,不会在子类中覆盖。
equals() method does not throw an exception at the time of comparing two Subset Objects.
在比较两个子集对象时, equals()方法不会引发异常。
Syntax:
句法:
public final boolean equals(Object value2);
Parameter(s):
参数:
Object value2 – represents the Object to compare with.
对象值2 –表示要比较的对象。
Return value:
返回值:
The return type of this method is boolean, it returns a boolean value based on the following value,
此方法的返回类型为boolean ,它基于以下值返回一个布尔值,
It returns true, if Object1 is same as Object2.
如果Object1与Object2相同,则返回true 。
It returns false, if Object1 is not same as Object2.
如果Object1与Object2不同 ,则返回false 。
Example:
例:
// Java program to demonstrate the example
// of boolean equals(Object value) method of
// Character.Subset class
public class EqualsOfCharacterSubset extends Character.Subset {
EqualsOfCharacterSubset(String str) {
super(str);
}
public static void main(String[] args) {
String str1 = new String("Java");
EqualsOfCharacterSubset value1 = new EqualsOfCharacterSubset(str1);
String str2 = new String("Programming");
EqualsOfCharacterSubset value2 = new EqualsOfCharacterSubset(str2);
boolean res = value1.equals(value2);
// Check equality of Character.Subset objects
if (res)
System.out.println("value1.equals(value2): " + res);
else
System.out.println("value1.equals(value2): " + res);
}
}
Output
输出量
value1.equals(value2): false
翻译自: https://www.includehelp.com/java/character-class-equals-method-with-example.aspx
java包装类equals