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

JavaÖжÔHashMapµÄÉî¶È·ÖÎö

ÔÚJavaµÄÊÀ½çÀÎÞÂÛÀ໹ÊǸ÷ÖÖÊý¾Ý£¬Æä½á¹¹µÄ´¦ÀíÊÇÕû¸ö³ÌÐòµÄÂß¼­ÒÔ¼°ÐÔÄܵĹؼü¡£ÓÉÓÚ±¾È˽Ӵ¥ÁËÒ»¸öÓйØÐÔÄÜÓëÂß¼­Í¬Ê±²¢´æµÄÎÊÌ⣬ÓÚÊǾͿªÊ¼Ñо¿Õâ·½ÃæµÄÎÊÌâ¡£ÕÒ±éÁË´ó´óССµÄÂÛ̳£¬Ò²°Ñ¡¶Java ÐéÄâ»ú¹æ·¶¡·£¬¡¶apress,.java.collections.(2001),.bm.ocr.6.0.shareconnector¡·£¬ºÍ¡¶Thinking in Java¡··­ÁËÒ²ÕÒ²»µ½ºÜºÃµÄ´ð°¸£¬ÓÚÊÇÒ»Æø֮ϰÑJDKµÄ src ½âѹ³öÀ´Ñо¿£¬À©È»¿ªÀÊ£¬Ëìд´ËÎÄ£¬¸ú´ó¼Ò·ÖÏí¸ÐÊܺÍ˳±ãÑéÖ¤ÎÒÀí½â»¹ÓÐûÓЩ¶´¡£ ÕâÀï¾ÍÄÃHashMapÀ´Ñо¿°É¡£
¡¡¡¡HashMap¿ÉνJDKµÄÒ»´óʵÓù¤¾ß£¬°Ñ¸÷¸öObjectÓ³ÉäÆðÀ´£¬ÊµÏÖÁË“¼ü£­£­Öµ”¶ÔÓ¦µÄ¿ìËÙ´æÈ¡¡£µ«Êµ¼ÊÀïÃæ×öÁËЩʲôÄØ£¿
¡¡¡¡ÔÚÕâ֮ǰ£¬ÏȽéÉÜһϸºÔØÒò×ÓºÍÈÝÁ¿µÄÊôÐÔ¡£´ó¼Ò¶¼ÖªµÀÆäʵһ¸ö HashMap µÄʵ¼ÊÈÝÁ¿¾Í Òò×Ó*ÈÝÁ¿£¬ÆäĬÈÏÖµÊÇ 16×0.75£½12£» Õâ¸öºÜÖØÒª£¬¶ÔЧÂʺÜÒ»¶¨Ó°Ï죡µ±´æÈëHashMapµÄ¶ÔÏ󳬹ýÕâ¸öÈÝÁ¿Ê±£¬HashMap ¾Í»áÖØй¹Ôì´æÈ¡±í¡£Õâ¾ÍÊÇÒ»¸ö´óÎÊÌ⣬ÎÒºóÃæÂýÂý½éÉÜ£¬·´Õý£¬Èç¹ûÄãÒѾ­ÖªµÀÄã´ó¸ÅÒª´æ·Å¶àÉÙ¸ö¶ÔÏó£¬×îºÃÉèΪ¸Ãʵ¼ÊÈÝÁ¿µÄÄܽÓÊܵÄÊý×Ö¡£
¡¡¡¡Á½¸ö¹Ø¼üµÄ·½·¨£¬putºÍget£º
¡¡¡¡ÏÈÓÐÕâÑùÒ»¸ö¸ÅÄHashMapÊÇÉùÃ÷ÁË Map£¬Cloneable, Serializable ½Ó¿Ú£¬ºÍ¼Ì³ÐÁË AbstractMap À࣬ÀïÃæµÄ Iterator ÆäʵÖ÷Òª¶¼ÊÇÆäÄÚ²¿ÀàHashIterator ºÍÆäËû¼¸¸ö iterator ÀàʵÏÖ£¬µ±È»»¹ÓÐÒ»¸öºÜÖØÒªµÄ¼Ì³ÐÁËMap.Entry µÄ Entry ÄÚ²¿À࣬ÓÉÓÚ´ó¼Ò¶¼ÓÐÔ´´úÂ룬´ó¼ÒÓÐÐËȤ¿ÉÒÔ¿´¿´Õⲿ·Ö£¬ÎÒÖ÷ÒªÏë˵Ã÷µÄÊÇ Entry ÄÚ²¿Àà¡£Ëü°üº¬ÁËhash£¬value£¬key ºÍnext ÕâËĸöÊôÐÔ£¬ºÜÖØÒª¡£putµÄÔ´ÂëÈçÏÂ
¡¡¡¡public Object put(Object key, Object value) {
¡¡¡¡Object k = maskNull(key);
¡¡¡¡Õâ¸ö¾ÍÊÇÅжϼüÖµÊÇ·ñΪ¿Õ£¬²¢²»ºÜÉî°Â£¬ÆäʵÈç¹ûΪ¿Õ£¬Ëü»á·µ»ØÒ»¸östatic Object ×÷Ϊ¼üÖµ£¬Õâ¾ÍÊÇΪʲôHashMapÔÊÐí¿Õ¼üÖµµÄÔ­Òò¡£
¡¡¡¡int hash = hash(k);
¡¡¡¡int i = indexFor(hash, table.length);
¡¡¡¡ÕâÁ¬ÐøµÄÁ½²½¾ÍÊÇ HashMap ×îÅ£µÄµØ·½£¡Ñо¿ÍêÎÒ¶¼º¹ÑÕÁË£¬ÆäÖÐ hash ¾ÍÊÇͨ¹ý key Õâ¸öObjectµÄ hashcode ½øÐÐ hash£¬È»ºóͨ¹ý indexFor »ñµÃÔÚObject tableµÄË÷ÒýÖµ¡£
¡¡¡¡table£¿£¿£¿²»Òª¾ªÑÈ£¬ÆäʵHashMapÒ²Éñ²»µ½ÄÄÀïÈ¥£¬Ëü¾ÍÊÇÓà table À´·ÅµÄ¡£×îÅ£µÄ¾ÍÊÇÓà hash ÄÜÕýÈ·µÄ·µ»ØË÷Òý¡£ÆäÖеÄhashËã·¨£¬ÎÒ¸úJDKµÄ×÷Õß Doug ÁªÏµ¹ý£¬Ëû½¨ÒéÎÒ¿´¿´¡¶The art of programing vol3¡·¿ÉºÞµÄÊÇ£¬ÎÒ֮ǰ¾ÍÒ»Ö±ÔÚÕÒ£¬ÎÒ¶¼ÕÒ²»µ½£¬Ë


Ïà¹ØÎĵµ£º

java tips

1£¬intÓëbytes ת»»
intת»»³Ébytes
public
static
final
byte
[]
int2bytes
(
int
value
)

{
return
new
byte
[]

{
(
byte
)(
value
>>>
24
),
(
byte
)(
value
>>>
16
),
......

java²¢·¢±à³Ìʵ¼ù ±Ê¼Ç£¨1£©

Ḭ̈߳²È« ʲôÊÇḬ̈߳²È«(thread-safe)£¿ Ò»¸öÀ࣬Èç¹ûÄܹ»ÔÚ¶àÏ̲߳¢·¢·ÃÎʵĻ·¾³Ï£¨²»¹ÜÏ̷߳ÃÎʵÄ˳Ðò£©ÕýÈ·±íÏÖ×Ô¼ºµÄÐÐΪ£¬²¢ÇÒÎÞÐèÍⲿµ÷ÓÃÌí¼ÓÈκÎͬ²½Ö®ÀàµÄ²Ù×÷£¬Õâ¸öÀà¾ÍÊÇḬ̈߳²È«µÄ¡£
Õâ¸öÕýÈ·ÐÔ¿ÉÒÔÕâôÀí½â£¬¾ÍÊÇ˵¶àÏ̷߳ÃÎʵĽá¹û²»»á²»Í¬ÓÚµ¥Ï̵߳ķÃÎÊ¡£
Ḭ̈߳²È«µÄÀ಻ÐèÒªÍⲿµ÷ÓÃÌá¹©È ......

Java¶ÔÏó¿½±´

public class Person implements Serializable {
    private String name;
    private int age;
    private GregorianCalendar birthday;
    public Person(){
       
    }
    p ......

´«ÖDz¥¿ÍJavaÅàѵ HTML»ù´¡Ê¾Àý

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>ʵÀý1</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME=" ......

¸ßЧÂÊjava±à³Ì

1:¿¼ÂÇʹÓþ²Ì¬¹¤³§·½·¨´úÌæ¹¹¹¹·½·¨À´ÊµÀý»¯Àà¡£
2£ºÊ¹ÓÃ˽Óù¹¹¹º¯Êý£¬Ê¹Àà¾ßÓв»¿ÉʵÀý»¯µÄÄÜÁ¦¡£
3£º±ÜÃâ´´½¨Öظ´µÄ¶ÔÏó
4£ºÏû³ý¹ýÆڵĶÔÏóµÄʹÓÃ
5£º±ÜÃâʹÓÃÖսắÊý
6£ºÊ¹ÀàºÍ³ÉÔ±µÄ¿É·ÃÎÊÐÔ×îС
7£º½Ó¿ÚÓÅÏÈÓÚ³éÏó
8£ºÎªËùÓеIJÎÊý½øÐÐÓÐЧÐÔ¼ì²é
9£º½÷É÷ʹÓÃÖØÔØ
10£ºÊ¹ÓÃ0³¤¶ÈµÄÊý×飬¶ø²»ÊÇ¿Õ
11£º½«¾ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ