Hashtable Dictionary ,HashMap Map HashTable ,HashMap HashTable , HashMap, HashTable。 HashTable , ? 。
1.HashTable ,HashMap , HashMap Vector ArrayList 。
2.HashTable null (key value ),HashMap null (key value )。HashMap key null , hashmap key , key, value 。
3.HashTable contains(Object value), containsValue(Object value) 。
4.HashTable Enumeration,HashMap Iterator。
, 。
5.HashTable hash 11, old*2+1。HashMap hash 16, 2 。
6. ,HashTable hashCode, :
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;
HashMap hash , :
int hash = hash(k);
int i = indexFor(hash, table.length);
static int hash(Object x) {
int h = x.hashCode();
h += ~(h << 9);
h ^= (h >>> 14);
h += (h << 4);
h ^= (h >>> 10);
return h;
}
static int indexFor(int h, int length) {
return h & (length-1);
}
, ,
HashMap null 。 HashMap :key Set,value Collection,Entry Set。 HashSet HashMap 。HashSet Hashmap , Hashmap Key Value 。
hashset
public boolean add(Object o) {
return map.put(o, PRESENT)==null;
}
HashMap , hash table , , key-value pair.HashSet , , hashCode()
HashMap hashcode , TreeMap , TreeMap(HashMap )
HashSet, TreeSet , , ; TreeSet , 。
Collections , :
SortedSet chaterNameSet ;
SortedMap nameToBean ;
chaterNameSet = Collections.synchronizedSortedSet(new TreeSet()) ;
nameToBean = Collections.synchronizedSortedMap(new TreeMap()) ;
// new TreeSet()
chaterNameSet = Collections.synchronizedSortedSet(new TreeSet()) ;
// new TreeMap()
nameToBean = Collections.synchronizedSortedMap(new TreeMap()) ;
synchronizedSortedSet() synchronizedSortedMap() ( ) 。 。 。
: synchronized