关于TreeMap

来源:互联网 发布:李炎恢php怎么样 编辑:程序博客网 时间:2024/06/07 22:46

关于可以看出TreeMap和HashMap查找不一样,TreeMap树遍历查找

    final Entry<K,V> getEntry(Object key) {        // Offload comparator-based version for sake of performance        if (comparator != null)            return getEntryUsingComparator(key);        if (key == null)            throw new NullPointerException();        Comparable<? super K> k = (Comparable<? super K>) key;        Entry<K,V> p = root;        while (p != null) {            int cmp = k.compareTo(p.key);            if (cmp < 0)                p = p.left;            else if (cmp > 0)                p = p.right;            else                return p;        }        return null;    }
0 0
原创粉丝点击