The TreeSet
will order on the elements you put in, not the order in which you put them in. A simple List
may suffice here if you don't need the hashing capability, or perhaps a LinkedHashSet (which maintains insertion order whilst iterating)
Hash table and linked list implementation of the Set interface, with predictable iteration order. This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order). Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation.)