多个字符串有相同的hashcode(没见到大于8的时候转成红黑树)

public static void main(String[] a){

byte[] b1 = {33 , 123 ,124};
byte[] b2 = {33 , 124 , 93};

byte[] b3 = {33 ,125, 62};
byte[] b4 = {34 , 92 , 124};

byte[] b5 = {34 , 93 , 93};
byte[] b6 = {34 , 94 , 62};

byte[] b7 = {35 , 61 ,124};
byte[] b8 = {35 , 62, 93};

byte[] b9 = {35 , 63, 62};
System.out.println( new String(b1).hashCode() +"\n"
+ new String(b1).hashCode() +"\n"
+ new String(b2).hashCode() +"\n"
+ new String(b3).hashCode() +"\n"
+ new String(b4).hashCode() +"\n"
+ new String(b5).hashCode() +"\n"
+ new String(b6).hashCode() +"\n"
+ new String(b7).hashCode() +"\n"
+ new String(b8).hashCode() +"\n"
+ new String(b9).hashCode() +"\n"


);

Map<String,Integer> map = new HashMap<String,Integer>();
map.put(new String(b1),1123);
map.put(new String(b2),1);
map.put(new String(b3),1);
map.put(new String(b4),1);
map.put(new String(b5),1);
map.put(new String(b6),1);
map.put(new String(b7),1);
map.put(new String(b8),1);
map.put(new String(b9),1);




System.out.println(123);
int abc= map.get(new String(b1));
System.out.println(abc);


}

posted on 2019-04-29 16:03  多情剑客无情剑;  阅读(179)  评论(0编辑  收藏  举报

导航