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/

  • 相关阅读:
    5+ App开发Native.js入门指南
    uni-app vue-cli命令行
    本地uni-app原生插件提交云端打包
    编写package.json文件
    生成插件包
    无障碍角色 accessibilityRole (iOS, Android)
    ajax 整理
    Javascript分享笔记
    echarts 横坐标分行展示,以及文字显示顶部
    js总结(11)js作用域
  • 原文地址:https://www.cnblogs.com/springfor/p/3859628.html
Copyright © 2011-2022 走看看