如题,部分源代码如下public class LinkedHashMap<K,V> extends HashMap<K,V>implements Map<K,V>{
    private final boolean accessOrder;
    public LinkedHashMap() {
super();
        accessOrder = false;
    }
    public HashMap() {
        this.loadFactor = DEFAULT_LOAD_FACTOR;
        threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
        table = new Entry[DEFAULT_INITIAL_CAPACITY];
        init();
    }
    public HashMap(int initialCapacity, float loadFactor) {
        if (initialCapacity < 0)
            throw new IllegalArgumentException("Illegal initial capacity: " +
                                               initialCapacity);
        if (initialCapacity > MAXIMUM_CAPACITY)
            initialCapacity = MAXIMUM_CAPACITY;
        if (loadFactor <= 0 || Float.isNaN(loadFactor))
            throw new IllegalArgumentException("Illegal load factor: " +
                                               loadFactor);        // Find a power of 2 >= initialCapacity
        int capacity = 1;
        while (capacity < initialCapacity)
            capacity <<= 1;        this.loadFactor = loadFactor;
        threshold = (int)(capacity * loadFactor);
        table = new Entry[capacity];
        init();
    }怎么看不到,关于Linked的代码,
LinkedHashMap,Map接口的哈希表和链接列表实现
又该如何理解,请赐教!

,小弟就70分了,我一般都是帖100分帖的

解决方案 »

  1.   

    下载JDK的源码就看到了。
    说明Map实现类内还有一个Link List成员而且,用于保存顺序。
      

  2.   

    void init() {
            header = new Entry<K,V>(-1, null, null, null);
            header.before = header.after = header;
        }这是源码里的init初始化方法,估计是利用了双向链表实现的。不知道我回答的对不对你的题...
      

  3.   

    LinkedHashMap 中的Linked主要是记录放入的顺序啊,它在Entry中有Entry<K,V> before, after这样的记录,所以它可以记录放入的顺序。不知道你是否问这个问题。
      

  4.   

    集合类框架图
                            collection
                    set               list      
                 hashset          linkedlist,vector,arraylist          hashtable,hashmap
                treeset                                                  treehmap
     从下往上是继承关系,也就是说上面的是父类,下面是子类。
    看错了,日,上面就当是复习下以前的知识吧。
         public class LinkedHashMap<K,V> extends HashMap<K,V>implements Map<K,V>{
        private final boolean accessOrder;
        public LinkedHashMap() {
        super();//父类的类方法,就是HashMap<K,V>的方法,和linked无关,是键值对在做类似指针的工
                 //做         
            accessOrder = false;
        }        
      

  5.   

    我贴的就是JDK的源代码,另外MAP里也没有 LinkList成员
      

  6.   

    保存顺序是靠LinkedHashMap.Entry类实现的,就在LinkedHashMap.java中    private static class Entry<K,V> extends HashMap.Entry<K,V> {
            // These fields comprise the doubly linked list used for iteration.
            Entry<K,V> before, after; Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
      

  7.   

    谢谢啊
    我找到了
        private static class Entry<K,V> extends HashMap.Entry<K,V> {
            // These fields comprise the doubly linked list used for iteration.
            Entry<K,V> before, after; Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {
                super(hash, key, value, next);
            }
    昨天晚上,没有找到Entry我以为还是用的HashMap.Entry
    原来LinkedHashMap又重写了Entry