首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

HASHMAP 写下两个对象,对象的hashcode不同,就有两个key

2012-10-25 
HASHMAP 写入两个对象,对象的hashcode不同,就有两个keyclass test {int idString name zhqang}HashM

HASHMAP 写入两个对象,对象的hashcode不同,就有两个key

 class test {              int id;              String name = "zhqang";        }        HashMap<Object, String> params = new HashMap<Object, String>();        params.put(new test(), "1");        params.put(new test(), "2"); Iterator iter = params.entrySet().iterator();        while (iter.hasNext()) {            Map.Entry entry = (Map.Entry) iter.next();            Object key = entry.getKey();            Object val = entry.getValue();            System.out.print(entry.getValue());        }



结果
 $1test@1f3aa07 -> 1 $1test@1a33d48 -> 2

热点排行