#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!