Programming architecture (03): Java collection container

Source code of this article: GitHub · click here | gitee · click here

1、 Introduction to collection containers

Collection container is the most basic API module in java development. It is usually used to store elements dynamically created at runtime. Its basic characteristics are as follows:

Here, the storage quantity is restricted by the program, memory and other environments. As can be seen from the get () method of list, the range of index is integer MAX_ VALUE。

2、 API system

Three core interfaces: list and set inherit collection, and map independent interface

List and set system

List system core APIs: ArrayList, LinkedList, vector

Set system core APIs: HashSet, TreeSet, linkedhashset

Queue API: PriorityQueue, linkedhashset

Map system

Core APIs of map system: HashMap, LinkedHashMap, treemap, hashtable

3、 Detailed explanation of foundation vessel

1. Core content

Basically proficient in using and understanding collection containers, you need to know the following: basic API usage, thread safety issues; Container size and expansion; Structural features, array, linked list, hash table;

2. API system details

Collection: the root interface of the collection container, defining public methods;

List system:

Maintain the implementation of object array. Features: fast query, slow addition and deletion, non thread safety, so high efficiency.

Low level maintenance linked list data structure implementation, features: slow query, fast addition and deletion, non thread safety, so high efficiency.

The object array is maintained at the bottom. The implementation is the same as ArrayList, but vector is thread safe and inefficient.

Set system:

The bottom layer is supported by hash table. Its characteristics are fast access, unique and unordered elements.

The underlying data structure is linked list and hash table. The linked list ensures the ordering of elements, and the hash table ensures the uniqueness of elements, which is non thread safe.

The data structure is a red black tree. If the elements have the characteristics of natural order, they will be sorted according to the characteristics of natural order of elements, or customized based on the comparator.

Map system:

The implementation class of map interface has the following characteristics: the stored data is in the form of key value pairs. The key can not be repeated and the value can be repeated.

The bottom layer uses the hashcode table to add elements to the HashMap. Null values and null keys are allowed, and the order of elements is not guaranteed.

Treemap: implemented based on binary tree data structure, it will sort and store the keys with natural characteristics: the keys of elements have natural characteristics and are directly sorted and stored; It does not have natural characteristics. It implements the comparable interface and defines sorting rules in comparato.

Thread safe, relatively inefficient, and null values are not allowed.

3. Container traversal

4、 Source code address

GitHub·地址
https://github.com/cicadasmile
GitEE·地址
https://gitee.com/cicadasmile

Recommended reading: Architecture Design Series

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>