获取java hashCode分布

 hashCode就是对象的散列码,是根据对象的某些信息推导出的一个整数值,默认情况下表示是对象的存储地址。通过散列码,可以提高检索的效率,主要用于在散列存储结构中快速确定对象的存储地址,如Hashtable、hashMap中。

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @title: 获取hashCode
 * @author: wll
 * @since: 2021-11-25 13:56:23
 */
public class TestHashCode {

	public static void main(String[] args) {

		List<String> hashList = new ArrayList<String>();
		
		for(int i=0;i<10;i++){hashList.add(i+" 3");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 4");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 5");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 6");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 7");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 8");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		for(int i=0;i<10;i++){hashList.add(i+" 9");}for(int i=0;i<hashList.size();i++){System.out.print(hashList.get(i).hashCode()+" ");}hashList.clear();System.out.println();
		
	}
}

数据结果: 

47171 48132 49093 50054 51015 51976 52937 53898 54859 55820 
47172 48133 49094 50055 51016 51977 52938 53899 54860 55821 
47173 48134 49095 50056 51017 51978 52939 53900 54861 55822 
47174 48135 49096 50057 51018 51979 52940 53901 54862 55823 
47175 48136 49097 50058 51019 51980 52941 53902 54863 55824 
47176 48137 49098 50059 51020 51981 52942 53903 54864 55825 
47177 48138 49099 50060 51021 51982 52943 53904 54865 55826 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值