I wonder why a HashSet uses a HashMap , a TreeSet uses a TreeMap , and a LinkedHashSet uses a LinkedHashMap inside behind the scene? since Set carries and stores the key, but the value, therefore, does not use additional memory space, for example, uneconomical?
The inner Entry class that the HashMap has is as follows
class Entry<K,V> implements Map.Entry<K,V> { final K key; V value; Entry<K,V> next; final int hash; ... .... }
For Set, we really don't need the V value variable, right? So, what is the use and the main reason for using the map object inside?
peter source share