• java学习_5_24


    TreeMap底层是用红黑树实现的,源码如下:

    /**
     * A Red-Black tree based {@link NavigableMap} implementation.
     * The map is sorted according to the {@linkplain Comparable natural
     * ordering} of its keys, or by a {@link Comparator} provided at map
     * creation time, depending on which constructor is used.
     *
     * <p>This implementation provides guaranteed log(n) time cost for the
     * {@code containsKey}, {@code get}, {@code put} and {@code remove}
     * operations.  Algorithms are adaptations of those in Cormen, Leiserson, and
     * Rivest's <em>Introduction to Algorithms</em>.
    */
    
    static final class Entry<K,V> implements Map.Entry<K,V> {
            K key;
            V value;
            Entry<K,V> left;
            Entry<K,V> right;
            Entry<K,V> parent;
            boolean color = BLACK;

    Set为一接口(没有顺序 不可重复),其实现类HashSet底层实现实为HashTable  JDK源码如下:

    public class HashSet<E>
        extends AbstractSet<E>
        implements Set<E>, Cloneable, java.io.Serializable
    {
        static final long serialVersionUID = -5024744406713321676L;
    
        private transient HashMap<E,Object> map;
    
        // Dummy value to associate with an Object in the backing Map
        private static final Object PRESENT = new Object();
    
        /**
         * Constructs a new, empty set; the backing {@code HashMap} instance has
         * default initial capacity (16) and load factor (0.75).
         */
        public HashSet() {
            map = new HashMap<>();
        }
    
    .............
      public boolean add(E e) {
            return map.put(e, PRESENT)==null;
        }
    
    ........
    }
  • 相关阅读:
    Android属性动画
    android 保存配置文档
    android 不自动弹出虚拟键盘
    android 常用代码
    android imageswitcher gallery 根据数据库内图片名字进行查看/删除
    android 文件内容和 textview 操作
    用 java 语言获取 1N 的不重复随机数
    android 数据库 备份还原
    解决Ubuntu 输入法不显示
    android 添加文本内容到sqlite表中
  • 原文地址:https://www.cnblogs.com/ustc-anmin/p/10920686.html
Copyright © 2020-2023  润新知