Java Object Class boolean equals(Object o)方法与示例
對象類布爾值等于(對象o) (Object Class boolean equals(Object o))
This method is available in package java.lang.Object.equals(Object o).
軟件包java.lang.Object.equals(Object o)中提供了此方法。
This method is used to check the object with the specified object.
此方法用于檢查具有指定對象的對象。
This method returns true if both Object reference and value are the same else return false.
如果Object引用和value相同,則此方法返回true,否則返回false。
Syntax:
句法:
boolean equals(Object o){}Parameter(s):
參數:
We pass only one object as a parameter in the method of the Object.
在對象的方法中,我們僅傳遞一個對象作為參數。
Return value:
返回值:
The return type of this method is boolean that means this method returns true if the reference and value of the object are the same.
此方法的返回類型為boolean ,這意味著如果對象的引用和值相同,則此方法返回true。
Java程序演示對象類equals()方法的示例 (Java program to demonstrate example of Object Class equals() method)
import java.lang.Object;public class ObjectClass {public static void main(String[] args) {// Create a new object of Integer typeInteger in1 = new Integer(10);// Create a new object of Float typeFloat fl = new Float(10.f);// Create another object of Integer typeInteger in2 = new Integer(20);// Create another object of Integer typeInteger in3 = new Integer(10);// Compare Integer and float type reference and value // and it returns true if both same else falseSystem.out.println("The result of comparing Integer and Float using equals():" + in1.equals(fl));// Compare Integer and another Integer type reference // and value and it returns true if both same else falseSystem.out.println("The result of comparing Integer and another Integer using equals():" + in1.equals(in2));// Compare Integer and another Integer type reference // and value and it returns true if both same else falseSystem.out.println("The result of comparing Integer and another Integer using equals():" + in1.equals(in3));} }Output
輸出量
D:\Programs>javac ObjectClass.javaD:\Programs>java ObjectClass The result of comparing Integer and Float using equals():false The result of comparing Integer and another Integer using equals():false The result of comparing Integer and another Integer using equals():true翻譯自: https://www.includehelp.com/java/object-class-boolean-equals-object-o-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java Object Class boolean equals(Object o)方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy zeros矩阵_零矩阵使用n
- 下一篇: c#象棋程序_C ++程序确定象棋方块的