I have spent alot
of time getting to know Collections.
It would be good if someone could confirm my understanding is correct?
I want to choose an implementation that:
1. Allows no duplicate keys
2. Sorts keys into order automatically
3. May allow null value, but they should not be allowed.
My understanding is that the TreeSet would be perfect for this implementation because
1. Lists are no good as they allow duplicate elements
2. HashSet/HashMap is no good because it is unordered
As TreeSet meets all the above criteria i.e. allows no duplicate keys, sorts keys into order automatically and may allow null value it meets my needs.
Is my understanding correct so far?
If this is the case why then, do examples show a Map being used to add and remove elements from unsorted map the convert to sorted map before displaying elements? Why not just go straignt to using a TreeMap?