Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the usage scenarios of the java collection framework

Shulou Source: shulou.com Published: 2022-06-01 18:33:35 09月24日 Update

This article introduces the relevant knowledge of "what are the scenarios for the use of the java collection framework". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. understanding of the framework of set

For the understanding of the collection framework, in order to prevent the impression from becoming blurred for a long time, I remember this method for reference, assuming that given a collection class, you can treat him as a person. first remember where you come from (inheritance relationships), then what skills (the underlying data structure determines the characteristics), and finally where to go (use scenarios).

According to the above idea, first look at the source (not to mention inheritance relationships here). Java collections are toolkits provided by java that contain common data structures: collections, linked lists, queues, stacks, arrays, maps, and so on. The location of the Java collection kit is java.util.*

What are you capable of? The Java collection has four main parts: the List list, the Set collection, the Map mapping, and the utility class (Iterator iterator, Enumeration enumeration class, Arrays, and Collections).

What about the usage scenario? In a word, each container (collection class) can hold a different liquid (data). Therefore, the function of the container is different in different usage scenarios.

II. Java collection class framework

For a clear understanding, take a picture.

It's too much, isn't it a little messy? don't worry. Now it's clear to sort them out.

First grasp its backbone, namely Iterator, Collection and Map. (the dummy line is the interface and the real line is the class)

1 、 Collection

A highly abstract interface that contains the basic operations of the set and attributes.

Collection includes two branches: List and Set. (1) List is an ordered queue, and there are 4 implementation classes: LinkedList, ArrayList, Vector, Stack.

(2) Set is a collection that does not allow repeating elements. There are three implementation classes: TreeSet, HastSet, and LinkHastSet.

2 、 Map

A mapping interface, the key-value key-value pair.

(1) AbstractMap is an abstract class that implements most of the API in Map interfaces. There are six implementation classes: TreeMap, HashMap, LinkHashMap, IdentityHashMap, WeakHashMap, HashTable (2) SortedMap are interfaces inherited from Map. The content is the sorted key-value pair through the comparator (Comparator)

3 、 Iterator .

It is a tool for traversing collections, that is, we usually traverse collections through Iterator iterators.

Third, the usage scenarios of each class of the overall framework of the collection

For the convenience of description, I think the picture is more intuitive.

Specifically, you can first have an impression. After you have learned all the collection classes, you will be a little more impressed.

This is the end of the content of "what are the scenarios for the use of the java collection framework". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Scenarios frameworks interfaces tools differences content impressions data containers toolkits data structures more skills knowledge structures queues iterations order anxiety intuition Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Shulou Tech Info Xiaomi Microsoft