Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÖÐhashmapºÍhashtableµÄÇø±ð

 
1¡¢  ¼Ì³ÐºÍʵÏÖÇø±ð
HashtableÊÇ»ùÓڳ¾ɵÄDictionaryÀàµÄ£¬HashMapÊÇJava 1.2Òý½øµÄMap½Ó¿ÚµÄÒ»¸öʵÏÖ¡£
2¡¢  Ḭ̈߳²È«²»Í¬
HashTableµÄ·½·¨ÊÇͬ²½µÄ£¬HashMapÊÇδͬ²½£¬ËùÒÔÔÚ¶àÏ̳߳¡ºÏÒªÊÖ¶¯Í¬²½HashMap¡£
3¡¢  ¶ÔnullµÄ´¦Àí²»Í¬
HashTable²»ÔÊÐínullÖµ(keyºÍvalue¶¼²»¿ÉÒÔ),HashMapÔÊÐínullÖµ(keyºÍvalue¶¼¿ÉÒÔ)¡£¼´HashTable ²»ÔÊÐínullÖµÆäʵÔÚ±àÒëÆÚ²»»áÓÐÈκεIJ»Ò»Ñù£¬»áÕÕÑùÖ´ÐУ¬Ö»ÊÇÔÚÔËÐÐÆÚµÄʱºòHashtableÖÐÉèÖõĻ°»Ø³öÏÖ¿ÕÖ¸ÕëÒì³£¡£HashMapÔÊÐí nullÖµÊÇÖ¸¿ÉÒÔÓÐÒ»¸ö»ò¶à¸ö¼üËù¶ÔÓ¦µÄֵΪnull¡£µ±get()·½·¨·µ»Ønullֵʱ£¬¼´¿ÉÒÔ±íʾ HashMapÖÐûÓиüü£¬Ò²¿ÉÒÔ±íʾ¸Ã¼üËù¶ÔÓ¦µÄֵΪnull¡£Òò´Ë£¬ÔÚHashMapÖв»ÄÜÓÉget()·½·¨À´ÅжÏHashMapÖÐÊÇ·ñ´æÔÚij¸ö¼ü£¬¶øÓ¦¸ÃÓÃcontainsKey()·½·¨À´Åжϡ£
4¡¢  ·½·¨²»Í¬
HashTableÓÐÒ»¸öcontains(Object value)£¬¹¦ÄܺÍcontainsValue(Object value)¹¦ÄÜÒ»Ñù¡£
5¡¢HashTableʹÓÃEnumeration£¬HashMapʹÓÃIterator¡£
6¡¢HashTableÖÐhashÊý×éĬÈÏ´óСÊÇ11£¬Ôö¼ÓµÄ·½Ê½ÊÇ old*2+1¡£HashMapÖÐhashÊý×éµÄĬÈÏ´óСÊÇ16£¬¶øÇÒÒ»¶¨ÊÇ2µÄÖ¸Êý¡£
7¡¢¹þÏ£ÖµµÄʹÓò»Í¬£¬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);
}
 
Çø±ð
 Hashtable
 Hashmap
 
¼Ì³Ð¡¢ÊµÏÖ
 Hashtable<K,V> extends Dictionary<K,V> implements Map<K,V>, Cloneable,Serializable
 HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable,Serializable
 
 
Ïß³Ìͬ²½
 ÒѾ­Í¬²½¹ýµÄ¿ÉÒÔ°²È«Ê¹ÓÃ
 Î´Í¬²½µÄ£¬¿ÉÒÔʹÓÃColletcions½øÐÐͬ²½Map Collections.synchronizedMap(Map m)
 
¶ÔnullµÄ´¦Àí
 
 Hashtable table = new Hashtable();
table.put(null, "Null");
t


Ïà¹ØÎĵµ£º

Effective Java ѧϰ±Ê¼Ç (11)

CloneÕâ¸ö·½·¨ºÜ¼¦Àߣ¬Ô­ÒòÊÇÒòΪËüÊÇÊܱ£»¤µÄ(protected)£¬Æä¶þCloneÕâ¸ö·½·¨ÊÇ¿ÉÑ¡µÄ£¬¼´ÓпÉÄÜÀàûÓÐÌṩÕâ¸ö·½·¨¡£
cloneûÓе÷Óù¹Ô캯Êý£¬¶øÇÒÈç¹û¸¸ÀàûÓÐʵÏÖcloneµÄ»°£¬×ÓÀàÓÀÔ¶Ò²²»¿ÉÄÜÕýȷʵÏÖclone.
×ÜÖ®£¬cloneÊǸöºÜÍ·Í´µÄº¯Êý£¬Èç¹ûÒªÕýȷʵÏÖ£¬±ØÐ뿼Âǵ½É±´µÄÇé¿ö£¬·ñÔò±»¿Ë¡³öÀ´µÄ¶ÔÏó¾Í²»ÊǶÀÁ¢µÄ ......

Effective Java ѧϰ±Ê¼Ç£¨13£©

Ó°ÏìÄ£¿éÉè¼ÆºÃÓ뻵µÄÒ»¸öÖØÒªÒòËؾÍÊÇÕâ¸öÄ£¿éÊÇ·ñÒþ²ØËüµÄÄÚ²¿Êý¾ÝºÍÆäËûһЩʵÏÖϸ½Ú¡£
ÐÅÏ¢Òþ²ØµÄºÃ´¦£º·½±ã¶ÀÁ¢¿ª·¢£¬²âÊÔ£¬ÓÅ»¯£¬Ê¹Óã¬Àí½âºÍÐ޸ġ£Äܹ»Ìá¸ßϵͳ¿ª·¢ËÙ£¨ÒòΪ¸÷Ä£¿é¿ÉÒÔ²¢Ðпª·¢£©£¬Ò²ÄÜÒ×ÓÚά»¤ºÍµ÷ÊÔ£¬Ò²ÄܼõÉÙϵͳ¹¹½¨µÄ·çÏÕ¡£
ÒªÉè¼ÆÁ¼ºÃµÄÄ£¿é£¬¹æÔòºÜ¼òµ¥£¬¾ÍÒ»¾ä»°£ºÊ¹Ã¿¸öÀà»ò½Ó¿Ú¾¡Á¿²»¿É ......

Java Web µÚÈýÌì Servlet´¦ÀíÏìÓ¦

Ò»¡¢
HTTP
ÏìÓ¦µÄ¸ñʽ
ÏìÓ¦ÐУº
HTTP
°æ±¾¡¢ÏìÓ¦Âë¡¢ÏìÓ¦ÃèÊö
ÏìӦͷ
¿ÕÐÐ
ÏûÏ¢Ìå
HTTP
ĬÈϵÄÎı¾±àÂëΪ£º
ISO-8895-1
¶þ¡¢
ÏìÓ¦ÂëµÄÉèÖÃ
1.      

ʲôÊÇÏìÓ¦Âë
ÏìÓ¦ÂëλÓÚ
HTTP
ÏìÓ¦µÄÏìÓ¦ÐÐÖУ¬ËûÓÃÀ´ÃèÊöµ±Ç°
Servlet
µÄһЩÖØÒªÐÅÏ¢¡£³£¼ûµÄÏìÓ¦ÂëÓÐ
200.302 ......

Java Ö±½ÓÑ¡ÔñÅÅÐò

      Ö±½ÓÑ¡ÔñÅÅÐòËã·¨£º´Ó´ýÅÅÐòµÄÊý¾ÝÔªËؼ¯ºÏÖÐÑ¡È¡×îСµÄÔªËطŵ½Ô­Ê¼Êý¾ÝµÄµÚÒ»¸öÔªËصÄλÖÃÉÏ¡£È»ºó²»°üÀ¨µÚÒ»¸öÔªËصÄÊý¾ÝÔªËؼ¯ºÏÖÐÕÒµ½×îСµÄÔªËطŵ½´Ë¼¯ºÏÖУ¬ÒÀ´ÎÀàÍÆ£¬¼´¿ÉÍê³ÉÅÅÐò¡£
Ë㷨ʵÏÖÈçÏ£º
/**
* Ö±½ÓÑ¡ÔñÅÅÐò
* @param a ÓÃÓÚÅÅÐòµÄÊý×é
* */
public void ......

Java "ÓÐÀíÓÉ" ±È C++ ¿ì

Java "ÓÐÀíÓÉ" ±È C++ ¿ì
 
×î½üÉÏCSDN±È½Ï¶à£¬ÓÖ¿´µ½ËµJava±ÈC++¸ü¿ìµÄÌû×Ó¡£
JavaÔÚijЩÇé¿öϱÈC++¿ìÎÒÈÏΪÊǺÜÓеÀÀíµÄ¡£ÀýÈç¿ÉÒÔ¸ù¾ÝÌض¨µÄCPU½øÐÐÓÅ»¯µÈµÈ¡£
ÓÐλ½Ð wingfiring(±ð¶ºÁË)(·ÇµäÐÍͺ×Ó) µÄÀÏÐÖ·¢ÁËÒ»¸öÌû×Ó£¬Ô­ÎÄÈçÏ£º
ºÃ£¬ÎÒûÄÇô¶àʱ¼ä³³C++ºÃ»¹ÊÇJavaºÃ£¬ËùÒÔ£¬ÎÒ¾ÍÏÈÕ°ÑöÒ»ÏÂÂ¥Ö÷¸ø³öµÄÁ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ