为什么在
HashSet
中添加null
不会抛出异常,但在TreeSet
中添加null
会抛出异常?Set<String> s = new TreeSet<String>();
s.add(null);
抛出 NullPointerException
异常
Set<String> s = new HashSet<String>();
允许添加null
值。