TreeSet and LinkedHashSet. When and which to use is an important question. In brief, if you need a fast set, you should use HashSet; if you need a sorted set, then TreeSet should be used; if you need a set that can
LinkedHashSetis in some sense intermediate betweenHashSetandTreeSet. Implemented as a hash table with a linked list running through it, howeverit provides insertion-ordered iteration which is not same as sorted traversal guaranteed by TreeSet. So choice of usage depends entirely on your needs but...
A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. Use this class instead of HashSet when you care about the iteration order. When you iterate through a HashSet the order is unpredictable, while a LinkedHashSet lets you iterate through ...