Home  >  Article  >  Java  >  What is the difference between list and map

What is the difference between list and map

王林
王林Original
2020-11-17 11:14:5922440browse

The difference between list and map is: 1. List is a collection that stores single-column data, and map is a collection that stores double-column data; 2. The data stored in list is ordered, and the data stored in map is Unordered; 3. The list is allowed to be repeated, the keys of the map cannot be repeated, and the values ​​can be repeated.

What is the difference between list and map

The difference between list and map is as follows:

list is a collection that stores single column data, and map stores keys and (key, value)} Such a collection of two-column data.

The data stored in List is in order and is allowed to be repeated; the data stored in Map is not in order and its keys cannot be repeated, but its values ​​can be repeated.

(Learning video sharing: java video tutorial)

Related introduction:

List features: elements have a placement order, and elements can be repeated.

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. The output order is the order of insertion.

4. Commonly used implementation classes include ArrayList, LinkedList and Vector. ArrayList is the most popular, providing casual access using indexes, while LinkedList is more suitable for situations where you frequently need to add or remove elements from a List.

Map:

1. It is not a sub-interface or implementation class of collection. Map is an interface.

2. Each Entry of Map holds two objects, that is, a key and a value. Map may hold the same value object but the key object must be unique.

3. TreeMap also maintains a sorting order through Comparator or Comparable.

4. You can have any number of null values ​​in the Map but there can only be at most one null key.

5. The most popular implementation classes of the Map interface are HashMap, LinkedHashMap, Hashtable and TreeMap. (HashMap and TreeMap are the most commonly used).

Related recommendations:Getting started with java

The above is the detailed content of What is the difference between list and map. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn