关于TreeSet和HashSet的addAll报错
使用TreeSet的addAll() 一个不为空的list集合结果报空指针,而使用HashSet却没有报错;
原因在于TreeSet底层是TreeMap,TreeMap的key不能为null
而HashSet的底层是HashMap,HashMap的key可以为null

博客讨论了TreeSet和HashSet的addAll方法报错问题。使用TreeSet的addAll添加非空list集合时会报空指针,而HashSet不会。原因是TreeSet底层是TreeMap,其key不能为null,HashSet底层是HashMap,其key可以为null。
关于TreeSet和HashSet的addAll报错
使用TreeSet的addAll() 一个不为空的list集合结果报空指针,而使用HashSet却没有报错;
原因在于TreeSet底层是TreeMap,TreeMap的key不能为null
而HashSet的底层是HashMap,HashMap的key可以为null

1770

被折叠的 条评论
为什么被折叠?