Java System类identityHashCode()方法及示例
系統(tǒng)類identityHashCode()方法 (System class identityHashCode() method)
identityHashCode() method is available in java.lang package.
identityHashCode()方法在java.lang包中可用。
identityHashCode() method is used to return the hashcode of the given object – By using this method the value of hashcode will be the same as the value of hashcode by using hashCode() method.
identityHashCode()方法用于返回給定對象的哈希碼–通過使用此方法,哈希碼的值將與使用hashCode()方法的哈希碼的值相同。
Let suppose, if we pass an object that holds null value then in that case, the value of hashCode will be 0.
假設(shè),如果我們傳遞一個持有null值的對象,則在這種情況下,hashCode的值將為0 。
identityHashCode() method is a static method so this method is accessible with the class name too.
identityHashCode()方法是靜態(tài)方法,因此也可以使用類名訪問此方法。
identityHashCode() method does not throw any exception.
identityHashCode()方法不會引發(fā)任何異常。
Syntax:
句法:
public static int identityHashCode(Object obj);Parameter(s):
參數(shù):
obj – represent the object for which the hashcode is to be returned.
obj –代表要為其返回哈希碼的對象。
Return value:
返回值:
The return type of this method is int, it returns the hashcode of the given argument.
此方法的返回類型為int ,它返回給定參數(shù)的哈希碼。
Example:
例:
// Java program to demonstrate the example of // identityHashCode () method of System Classimport java.lang.*; import java.io.*;public class IdentityHashCodeMethod {public static void main(String[] args) throws Exception {File file1 = new File("Java");File file2 = new File("Programming");// getting hashcodeint hcode1 = System.identityHashCode(file1);System.out.println(hcode1);// getting hashcodeint hcode2 = System.identityHashCode(file2);System.out.println(hcode2);} }Output
輸出量
E:\Programs>javac IdentityHashCodeMethod.java E:\Programs>java IdentityHashCodeMethod 1018081122 242131142翻譯自: https://www.includehelp.com/java/system-class-identityhashcode-method-with-example.aspx
總結(jié)
以上是生活随笔為你收集整理的Java System类identityHashCode()方法及示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: to_number用法示例_Number
- 下一篇: java美元兑换,(Java实现) 美元