类图

HashSet和TreeSet的区别:https://www.cnblogs.com/bobi1234/p/10759769.html
HashSet和LinkedHashSet区别:https://www.cnblogs.com/bobi1234/p/10759775.html

ArrayList和Vector的区别:https://www.cnblogs.com/bobi1234/p/10759767.html
ArrayList和LinkedList的区别:https://www.cnblogs.com/bobi1234/p/10759765.html

HashMap和Hashtable的区别:https://www.cnblogs.com/bobi1234/p/10759778.html
HashMap和TreeMap的区别:https://www.cnblogs.com/bobi1234/p/10759779.html
HashMap与ConcurrentHashMap的区别:https://www.cnblogs.com/bobi1234/p/10759800.html
HashMap和LinkedHashMap的区别:https://www.cnblogs.com/bobi1234/p/10759823.html

List数据是否可重复、可为空、可为null

public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("11");
        list.add("22");
        list.add("33");
        list.add("11");
        list.add("");
        list.add(null);
        System.out.println(list);
        List<String> list2 = new LinkedList<>();
        list2.add("11");
        list2.add("22");
        list2.add("33");
        list2.add("11");
        list2.add("");
        list2.add(null);
        System.out.println(list2);
    }
}
[11, 22, 33, 11, , null]
[11, 22, 33, 11, , null]
结论:ArrayList和LinkedList的值可重复、可为空、可为null

Set数据是否可重复、可为空、可为null

public class SetDemo {
    public static void main(String[] args) {
        Set<String> set = new HashSet<>();
        set.add("11");
        set.add("22");
        set.add("33");
        set.add("11");
        set.add("");
        set.add(null);
        System.out.println(set);
        Set<String> set2 = new LinkedHashSet<>();
        set2.add("11");
        set2.add("22");
        set2.add("33");
        set2.add("11");
        set2.add("");
        set2.add(null);
        System.out.println(set2);
    }
}
[11, 22, 33, , null]
[11, 22, 33, , null]
结论:HashSet和LinkedHashSet的值不能重复,但可为空,可为null

Map数据是否可重复、可为空、可为null

public class MapDemo {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("语文", 100);
        map.put("数学", 99);
        map.put("语文", 98);
        map.put("", 97);
        map.put(null, 96);
        map.put(null, null);
        System.out.println(map);
        Map<String, Integer> map2 = new TreeMap<>();
        map2.put("语文", 100);
        map2.put("数学", 99);
        map2.put("语文", 98);
        map2.put("", 97);
        map2.put("外语", null);
        // map2.put(null, 96);   NullPointerException
        // map2.put(null, null); NullPointerException
        System.out.println(map2);
    }
}
{=97, null=null, 数学=99, 语文=98}
{=97, 外语=null, 数学=99, 语文=98}
结论:
HashMap的key不可重复,但可为空、可为null,value不做讨论。
TreeMap的key不可重复、不可为null,但可为空,value不做讨论。

最新文章

  1. [转]jquery遍历table的tr获取td的值
  2. 【三石jQuery视频教程】03.创建垂直时间表(Timeline)
  3. Java中用户界面布局
  4. programing Python --Sys module
  5. cardsui-for-android
  6. unity3d自己写角色移动脚本
  7. linux使用crontab -e 遇到No space left on device
  8. MySQL存储过程实例
  9. Linux下的Job Control(转:http://blog.chinaunix.net/uid-26495963-id-3062757.html)
  10. NonUniqueObjectException 问题
  11. 提升Mac os x 10.10+xcode6.1之后,Cocoapods发生故障的解决方案
  12. PowerShell学习小结
  13. spring cloud+dotnet core搭建微服务架构:配置中心续(五)
  14. Linux Redis集群搭建与集群客户端实现
  15. 小tips:path的join和resolve的使用区别
  16. HTML div 盒子 添加/删除——浮层
  17. windows下手动安装composer并配置环境变量
  18. Windows补丁更新Tips
  19. boost asio 学习(六) 定时器
  20. python之工作举例:通过复制NC文件来造数据

热门文章

  1. 使用shell快速建立上万个文件夹
  2. 彻底搞懂spark的shuffle过程(shuffle write)
  3. ABP之调试
  4. 核主成分分析方法(KPCA)怎么理解?
  5. [转帖]Qemu 简述
  6. Django2 Django MTV模板
  7. jqgrid的增删改查
  8. LOJ2276 [HAOI2017] 新型城市化 【二分图匹配】【tarjan】
  9. windows系统下升级nodejs
  10. package.json 中script脚本传入参数问题