The characteristics and differences of List, Set, Map

List:
1. Duplicate objects can be allowed.
2. You can insert multiple null elements.
3. It is an ordered container that maintains the insertion order of each element, and the output order is the insertion order.
4. Commonly used implementation classes are ArrayList, LinkedList and Vector. ArrayList is the most popular, it provides free access using indexes, and LinkedList is more suitable for occasions where you often need to add or remove elements from the List.

==============================================
Set:
1. No Allow repeating objects
2. Unordered container, you cannot guarantee the storage order of each element, TreeSet maintains a sort order through Comparator or Comparable.
3. Only one null element is allowed.
4. The most popular implementation classes of the Set interface are HashSet, LinkedHashSet and TreeSet. The most popular is HashSet based on HashMap; TreeSet also implements the SortedSet interface, so TreeSet is an ordered container sorted according to its compare() and compareTo() definitions.

=============================================

Map:
1. Map is not a sub-interface or implementation class of collection. Map is an interface.
2. Each Entry of Map holds two objects, that is, one key and one value. Map may hold the same value object but the key object must be unique.
3. TreeMap also maintains a sort order through Comparator or Comparable.
4. You can have any number of null values ​​in the Map, but there can only be one null key at most.
5. The most popular implementation classes of the Map interface are HashMap, LinkedHashMap, Hashtable and TreeMap. (HashMap and TreeMap are most commonly used)

Guess you like

Origin blog.csdn.net/Hambur_/article/details/110354369