Home  >  Article  >  Java  >  The difference between set and list in java

The difference between set and list in java

(*-*)浩
(*-*)浩Original
2019-12-27 09:53:533238browse

The difference between set and list in java

#The List collection includes the JavaList interface and all implementation classes of the List interface.

Elements in the List collection are allowed to be repeated, and the order of each element is the order in which the object is inserted.                                                                                                                                                                                                (Recommended Learning: java Course)

Similar to an array in Java, users can access elements in a collection by using an index (the position of the element in the collection).

Set: Pays attention to the unique nature. This system collection can know whether something already exists in the set and will not store duplicate elements.

is used to store unknown elements. Sequential (the order of depositing and taking out is not necessarily the same) elements, the value cannot be repeated.

The difference between Set and List

1. The Set interface instance stores unordered and non-duplicate data. List interface instances store ordered, repeatable elements.

2. Set retrieval efficiency is low, while deletion and insertion efficiency are high. Insertion and deletion will not cause the position of elements to change. .

3. List is similar to an array and can grow dynamically. The length of the List automatically increases according to the length of the actual stored data. The efficiency of finding elements is high, but the efficiency of insertion and deletion is low, because it will cause the position of other elements to change .

The above is the detailed content of The difference between set and list in java. 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