zoukankan      html  css  js  c++  java
  • HashTable HashMap HashSet区别(java)

    Hashtable:

     1. key和value都不许有null值

     2. 使用enumeration遍历

     3. 同步的,每次只有一个线程能够访问

     4. 在java中Hashtable是H大写,t小写,而HashMap是H大写,M大写

    HashMap:

     1. key和value可以有null值

     2. 使用iterator遍历

     3. 未同步的,多线程场合要手动同步HashMap

     HashSet

     1. 底层调用HashMap

     2. 不允许有重复值

     常用Java操作:

     1         Hashtable<Integer, Integer> ht=new Hashtable<Integer, Integer>();
     2         ht.put(key, value);
     3         ht.containsKey(key);
     4         ht.containsValue(value);
     5         ht.remove(key);
     6         ht.remove(key, value);

     7         HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
     8         hm.put(key, value);
     9         hm.containsKey(key);
    10         hm.containsValue(value);
    11         hm.remove(key);
    12         hm.remove(key, value);

    13         HashSet<Integer> hs = new HashSet<Integer>();
    14         hs.add(e);
    15         hs.contains(o);
    16         hs.remove(o);

     

    Reference:

    http://blog.sina.com.cn/s/blog_4586764e0100ivup.html

    http://www.blogjava.net/fisher/archive/2006/12/13/87398.html

    http://blog.csdn.net/wl_ldy/article/details/5941770

    http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/

  • 相关阅读:
    web Function函数
    web语言发展史
    用户正则
    字符串替换
    css单位
    JavaScript DOM&BOM
    css颜色的设置
    pseudo-class与pseudo-element的不同点与相同点
    对css语法中position值的理解
    API
  • 原文地址:https://www.cnblogs.com/springfor/p/3859628.html
Copyright © 2011-2022 走看看