为什么加null在HashSet没有抛出Exception,但添加null在TreeSet抛出异常。
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添加值。