zoukankan      html  css  js  c++  java
  • HashTable的构造函数有哪些

    HashTable:在并发的环境下,使用synchronized将整张表锁住;

    HashTable构造函数有:

    1. public Hashtable(int initialCapacity, float loadFactor)
    2. public Hashtable(int initialCapacity)
    3. public Hashtable()
    4. public Hashtable(Map<? extends K, ? extends V> t)
    /**
         * Constructs a new, empty hashtable with the specified initial
         * capacity and the specified load factor.
         *
         * @param      initialCapacity   the initial capacity of the hashtable.
         * @param      loadFactor        the load factor of the hashtable.
         * @exception  IllegalArgumentException  if the initial capacity is less
         *             than zero, or if the load factor is nonpositive.
         */
        public Hashtable(int initialCapacity, float loadFactor) {
            if (initialCapacity < 0)
                throw new IllegalArgumentException("Illegal Capacity: "+
                                                   initialCapacity);
            if (loadFactor <= 0 || Float.isNaN(loadFactor))
                throw new IllegalArgumentException("Illegal Load: "+loadFactor);
    
            if (initialCapacity==0)
                initialCapacity = 1;
            this.loadFactor = loadFactor;
            table = new Entry<?,?>[initialCapacity];
            threshold = (int)Math.min(initialCapacity * loadFactor, MAX_ARRAY_SIZE + 1);
        }
    
        /**
         * Constructs a new, empty hashtable with the specified initial capacity
         * and default load factor (0.75).
         *
         * @param     initialCapacity   the initial capacity of the hashtable.
         * @exception IllegalArgumentException if the initial capacity is less
         *              than zero.
         */
        public Hashtable(int initialCapacity) {
            this(initialCapacity, 0.75f);
        }
    
        /**
         * Constructs a new, empty hashtable with a default initial capacity (11)
         * and load factor (0.75).
         */
        public Hashtable() {
            this(11, 0.75f);
        }
    
        /**
         * Constructs a new hashtable with the same mappings as the given
         * Map.  The hashtable is created with an initial capacity sufficient to
         * hold the mappings in the given Map and a default load factor (0.75).
         *
         * @param t the map whose mappings are to be placed in this map.
         * @throws NullPointerException if the specified map is null.
         * @since   1.2
         */
        public Hashtable(Map<? extends K, ? extends V> t) {
            this(Math.max(2*t.size(), 11), 0.75f);
            putAll(t);
        }
  • 相关阅读:
    测试开发进阶——spring boot——MVC——thymeleaf模板——通过Model model的model.addAttribute返回数据给模板——示例01
    测试开发进阶——spring boot——MVC——thymeleaf模板——打开网页
    git小笔记
    web.config中sessionState节点的配置方案
    【BZOJ1053】 反素数ant
    正则表达式 (python 2)
    简政放权是合理的,大道至简
    一本通1035
    一本通1033
    Oracle中事务隔离机制
  • 原文地址:https://www.cnblogs.com/hujinshui/p/9950075.html
Copyright © 2011-2022 走看看