Home > Java > javaTutorial > body text

What are Java collections?

青灯夜游
Release: 2019-11-18 17:59:25
Original
4989 people have browsed it

What are Java collections?

There are three main types of Java collections: set (set), list (list) and map (mapping).

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

The objects stored in the List are ordered and can be Repeatedly, List focuses on indexes, has a series of index-related methods, and has fast query speed. Because when inserting or deleting data into the list collection, it will be accompanied by the movement of subsequent data, all insertion and deletion of data are slow.

1. ArrayList collection:

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

2), thread unsafe, high efficiency

2, Vector collection:

1) The underlying data structure is an array, with fast query, addition and deletion Slow

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)

The objects stored in Set are unordered and cannot be repeated. The objects in the set are not sorted in a specific way. The objects are simply added to the set.

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 sequence 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 and does not add

is false: just add the element directly

No: just add it directly to the collection

2, Treeset collection :

1) The underlying data structure is a binary tree

3. Map collection

Stored in the Map collection It is a key-value pair, the key cannot be repeated, and the value can be repeated. Obtain the value according to the key. When traversing the map collection, first obtain the set collection of the key, traverse the set collection, and obtain the corresponding value.

1. Map collection is the root interface of the Map collection family. It has two subclasses: HashMap and TreeMap collections.

2. The Map collection is only valid for keys, but not for values.

3. Data structure of subclasses:

Hashmap: The underlying data structure is a hash table, and the underlying data structure of Treemap is a binary tree, whose properties are the same as the underlying data structure of Set.

Recommended tutorial: Java tutorial

The above is the detailed content of What are Java collections?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template