hashcode

hashCode是jdk根据对象的地址或者字符串或者数字算出来的int类型的数值 详细了解请 参考 public int hashCode()返回该对象的哈希码值。支持此方法是为了提高哈希表(例如 java.util.Hashtable 提供的哈希表)的性能
package com.yiibai;

import java.math.*;

public class BigDecimalDemo {

    public static void main(String[] args) {

        // create 3 BigDecimal objects
        BigDecimal bg1, bg2, bg3;

        // create 3 int objects
        int i1, i2, i3;

        bg1 = new BigDecimal("125");
        bg2 = new BigDecimal("125.50");
        bg3 = new BigDecimal("125.80");

        // assign the HashCode value of bg1, bg2, bg3 to i1, i2, i3
        // respectively
        i1 = bg1.hashCode();
        i2 = bg2.hashCode();
        i3 = bg3.hashCode();

	String str1 = "HashCode of " + bg1 + " is " + i1;
	String str2 = "HashCode of " + bg2 + " is " + i2;
	String str3 = "HashCode of " + bg3 + " is " + i3;

	// print i1, i2, i3 values
        System.out.println( str1 );
        System.out.println( str2 );
        System.out.println( str3 );
    }
}
让我们编译和运行上面的程序,这将产生以下结果:
HashCode of 125 is 3875
HashCode of 125.50 is 389052
HashCode of 125.80 is 389982

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值