Java System类identityHashCode()方法及示例

系统类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.

    假设,如果我们传递一个持有null值的对象,则在这种情况下,hashCode的值将为0

  • identityHashCode() method is a static method so this method is accessible with the class name too.

    identityHashCode()方法是静态方法,因此也可以使用类名访问此方法。

  • identityHashCode() method does not throw any exception.

    identityHashCode()方法不会引发任何异常。

Syntax:

句法:

    public static int identityHashCode(Object obj);

Parameter(s):

参数:

  • 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 ,它返回给定参数的哈希码。

Example:

例:

// Java program to demonstrate the example of 
// identityHashCode () method of System Class

import 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 hashcode
        int hcode1 = System.identityHashCode(file1);
        System.out.println(hcode1);

        // getting hashcode
        int 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

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值