The difference between List, set and map

List and set implement the collection interface
List : 1. Duplicate objects can be allowed
2. Multiple null elements can be inserted
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 ArryList, LinkedList and Vector ArryList are the most popular. It provides free access using indexes, while LinkedList is more suitable for occasions where you often need to add or remove elements from the List.

Set : 1. Duplicate objects are not allowed
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 Set interface The implementation classes are HashSet, LinkedHashSet and TreeSet. The most popular is HashSet based on HashMap. TreeSet also implements the SortrdSet interface.
Therefore, TreeSet is an ordered container that sorts according to its compare() and compareTo() definitions.

Map : Not a subclass interface or implementation class of collection. Map is an interface
1. 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 It is the only one
2. TreeMap also maintains a sort order through Comparator or Comparable
3. You can have any null value in the
Map but only one null key 4. The most popular implementation classes of the Map interface are HashMap and LinkedHashMap , Hashtable and TreeMap (HashMap, TreeMap are the most commonly used)

Summary: list set map

  1. The elements in the list are ordered, repeatable, and empty;
  2. The elements in the set are disordered, non-repetitive, and have only one empty element;
  3. The elements in the map are unordered, the keys are not heavy, the values ​​can be repeated, one empty key, multiple empty values

Guess you like

Origin blog.csdn.net/weixin_43464372/article/details/108294452