Home>Article>Java> What are collections in java

What are collections in java

王林
王林 Original
2019-11-15 15:40:54 8265browse

What are collections in java

1. List collection: (ordered, elements can be repeated)

1. ArrayList collection:

1) The underlying data structure is an array, which is fast to search but slow to add and delete.

2) Thread is not safe and efficient

2. Vector collection:

1) The underlying data structure is an array, which is fast to query and slow to add and delete.

2) Thread safety, low efficiency

3. LinkedList collection:

1) The underlying data structure is a linked list, which is slow to query and fast to add and delete

2) Thread unsafe, high efficiency

2. Set collection (elements cannot be repeated, elements are unique)

1. Hashset collection :

1) The underlying data structure is a hash table, and the hash table relies on two methods, hascode () and equals () method

2) The execution order of the two methods:

First determine whether the hascode() values are the same

Yes: continue to execute the equals() method and see its return value

is true: it means that the elements are repeated, do not add

is false: add the element directly

No: add it directly to the collection

2, Treeset collection:

1) Bottom layer The data structure is a binary tree

Recommended tutorial:Java tutorial

The above is the detailed content of What are collections 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