1、Set
The HashSet stores elements using a rather complex approach that will be explored in the Containers in Depth chapter—all you need to know at this point is that this technique is the fastest way to retrieveelements, and as a result the storage order can seem nonsensical (often, you only care whether something is a member of the Set, not the order in which it appears). If storage order is important, you can use a TreeSet, which keeps the objects in ascending comparison order, or a LinkedHashSet, which keeps the objects in the order in which they were added.
(1)、HashSet:HashSet集合判断两个元素相等的标准是两个对象通过equals方法比较相等,并且两个对象的HashCode()方法返回值也相等——也就是说HashSet会在两个条件都满足的情况下才会判断两个元素相等
但在实际实现时应该注意:如果需要某个类的对象保存到HashSet集合中,重写这个类的equals()方法和HashCode()方法时,应该尽量保证两个对象通过equals()方法比较返回true时,他们的HashCode方法返回值也相等
根据《Effective Java》第九条所说:“Always override hashCodewhen you override equals(覆盖equals总要覆盖hashCode)”;equal objects must have equal hash codes
Set的三个实现类HashSet、TreeSet和EnumSet都是线程不安全的
关于Set-List-Map的比较学习,布布扣,bubuko.com
原文:http://www.cnblogs.com/CoolRandy/p/3658557.html