zoukankan      html  css  js  c++  java
  • HashTable HashMap HashSet区别(java) [From 爱做饭的小莹子]

    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 
     8 HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
     9         hm.put(key, value);
    10         hm.containsKey(key);
    11         hm.containsValue(value);
    12         hm.remove(key);
    13         hm.remove(key, value);
    14         
    15 HashSet<Integer> hs = new HashSet<Integer>();
    16         hs.add(e);
    17         hs.contains(o);
    18         hs.remove(o);

    Reference:

    http://www.cnblogs.com/springfor/p/3859628.html

    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/

  • 相关阅读:
    Java 之 Junit 单元测试
    数据结构和算法概述
    数组模拟队列
    单链表
    链表(Linked List)
    其它/编程 error201599
    SQL Server 生成 数据字典 / 数据库文档
    其它/编程 error2016420
    其它/编程 error2016118
    MySQL 数据 导入到 SQL Service
  • 原文地址:https://www.cnblogs.com/hygeia/p/4553624.html
Copyright © 2011-2022 走看看