I've been using TreeMap<String,Object> to store objects as they don't allow entries with duplicate keys,
Is there a a similar data structure that only takes in a value/key and doesn't allow duplicate entries?
so something like Type<String> where all the Strings have to be different (or they overwrite)
until now ive just been using Vector<String> with checks to see if an entry is already in the vector before adding it which is a bit messy.
Set is what you are looking for. There are couple of implementations of this interface. The most common is the HashSet (fast contains() operation but the order is not guaranteed), TreeSet (this is actually implementation of SortedSet, the instances stored in TreeSet should implement Comparable) and the last commonly used is the LinkedHashSet. The order of LinkedHashSet is derived from the time elements were added into the container.
Recently, I saw this handy diagram: 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With