Java, List, Set features a separate collection and use

Separate collection framework

                                       

Collection: single root interface collection class, for storing a series of elements meet certain rules. Set List and its sub-interfaces

List: is the ordered set, store and retrieve the same element order. It allows storing duplicate elements. An index, you can use ordinary for loop

Set: Storage is not repeating elements. There is no index (can not use ordinary for loop iterates).

 

Detailed List:

Since List is indexed, it is possible, according to the index increase at a particular location, returned, removed, replaced, data

public void add(int index,E element)

public E get(int index)

public E remove(int index)

public E set(int index,E element)

 

ArrayList

The underlying array structures, additions and deletions slow, fast look. Each add an element, all you need to create a new ArrayList, copy the old data plus new elements.

LinkedList

The bottom of the list structure, look slow, fast additions and deletions. Head and tail of the list is a good query, so there are a lot of additions and deletions head element and the tail element change search.

Vector

Single-threaded array

 

Set Detailed

HashSet

Miscellaneous storage element, and the element will not be repeated.

When adding elements rely HashCode () method to calculate a hash value,

Without the hash value is stored, returns to true.

If the hash value, through equals () method for determining values ​​of two elements, if two elements are equal, the hash will produce a conflict, it returns false. If not equal, put the storage element to the collection, return true.

LinkedHashSet

+ Underlying hash table linked list order of the elements can be recorded, it is possible to ensure an orderly elements.

Published 62 original articles · won praise 39 · views 120 000 +

Guess you like

Origin blog.csdn.net/liangjiabao5555/article/details/103524970