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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.
