
本文共 3424 字,大约阅读时间需要 11 分钟。
HashMap ���Java���������������������������������������������HashMap ������������������������������������������������������������������HashMap ���������������������������������������������������������������������������������������
������HashMap ������
���������������������HashMap ������������������������������������HashMap ������������������������������������������������������Entry���Entry ������������������������������HashMap ������������Entry ������������������Hash()������������������������������Entry������������������������������������������������������������for���������������������������������������������������HashMap ������
1. ������EntrySet������
HashMap ������������������EntrySet������������������������������������HashMap ������������������Entry���������������������������������HashMap���
HashMapmap=new HashMap ();
������������������������EntrySet���
Set> entrySet=map.entrySet();
������������������HashMap ������������Entry���������Entry ���������������������������������������������foreach ������������
Set> entrySet=map.entrySet();for (Entry entry : entrySet) { System.out.println(entry.getKey()+":"+entry.getValue()); }
���������������������������������
Iterator> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); System.out.println(entry.getKey()+":"+entry.getValue()); }
2.������KeySet ������
HashMap ������KeySet������������������Map������������������������set���������������������get������������������������������������������������������ ������KeySet ���������������������:
for (String key : map.keySet()) { System.out.println(key+":"+map.get(key)); }
���������������������������������Hashmap ������������value���������������values ������������������������������������������value ���collection���
Collectioncollection = map.values();System.out.println(collection);
������������������
���������������������������������������������������������������������������������������������������������������������������EntrySet ������������������������������������������������������������������������������foreach������������������������������������EntrySet ������������������������KeySet���������������������������������KeySet������������������������������������������������KeySet ������������get() ������������������JDK 1.6 ver������
public V get(Object key) { if (key == null) return getForNullKey(); int hash = hash(key.hashCode()); for (Entrye = table[indexFor(hash, table.length)]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) return e.value; } return null; }
������������������������������������key ���������hash��� ���������������hash������HashMap ���Entry ������������������hash������key���hash������������Entry���������������������Value���������get() ���������������Value ������������������������������������������������������������������
������������
������������������������������������������HashMap ������������������������EntrySet������������������KeySet������������EntrySet ������KeySet ���������������KeySet ���get���������������Value ������������������������������������������������HashMap ���������������EntrySet ������������
发表评论
最新留言
关于作者
