小编V.S*_*V.S的帖子

为什么在HashSet中添加null不会引发异常,而在TreeSet中添加null会引发异常

为什么加nullHashSet没有抛出Exception,但添加nullTreeSet抛出异常。

Set<String>  s = new TreeSet<String>();
        s.add(null);
Run Code Online (Sandbox Code Playgroud)

抛出 NullPointerException

Set<String>  s = new HashSet<String>();
Run Code Online (Sandbox Code Playgroud)

允许Null添加值。

java hashset treeset

2
推荐指数
1
解决办法
9060
查看次数

标签 统计

hashset ×1

java ×1

treeset ×1