search
HomeJavaJavaBaseWhat are java collections

What are java collections

Nov 14, 2019 am 10:10 AM
javalistsetgather

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version