Home > Java > JavaBase > What are java collections

What are java collections

angryTom
Release: 2019-11-14 10:10:40
Original
3461 people have browsed it

What are java collections

What are the Java collections?

The collection classes used in the Java API all implement the Collection interface. A class inheritance structure is as follows:

Collection

Collection

Collection

Collection

Collection

Collection

What are java collections

Vector

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

2) Thread-safe and low efficiency

List based on Array actually encapsulates some functions that Array does not have for our use. It cannot fall into the limitations of Array. It is impossible to surpass Array in performance. Therefore, where possible, we should use Array more. Another very important point is that Vector is "sychronized", which is also the only difference between Vector and ArrayList.

ArrayList

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

2). Thread unsafe and high efficiency

Like Vector, it is a linked list based on Array, but the difference is that ArrayList is not synchronized. Therefore, it is superior to Vector in terms of performance, but when running in a multi-threaded environment, you need to manage the synchronization of threads yourself.

LinkedList

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

2) Thread-unsafe and high efficiency

LinkedList is different from the previous two Lists in that it is not based on Array, so it is not limited by Array performance. Each node (Node) contains two aspects of content:

1. The data of the node itself (data);

2. The information of the next node (nextNode). Therefore, when adding and deleting actions to a LinkedList, there is no need to move a large amount of data like an Array-based List. Just change the relevant information of nextNode and you can achieve it. This is the advantage of LinkedList.

Hashset collection:

1) The underlying data structure is a hash table, which 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

Yes true: It means the element is repeated, no

is added. False: Just add the element directly

No: Just add it directly to the collection

Treeset collection:

1) The underlying data structure is a binary tree

Summary:

1. All Lists can only hold a single table composed of objects of different types. , rather than Key-Value key-value pairs. For example: [tom,1,c];

2. All Lists can have the same elements, for example, Vector can have [tom,koo,too,koo];

3 . All lists can have null elements, such as [tom,null,1];

4. Array-based List (Vector, ArrayList) is suitable for query, while LinkedList (linked list) is suitable for addition and deletion operations.

HashSet: Although Set and List both implement the Collection interface, their implementation methods are quite different. List is basically based on Array. But Set is implemented on the basis of HashMap. This is the fundamental difference between Set and List. The storage method of HashSet is to use the Key in HashMap as the corresponding storage item of Set.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

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