Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the usage scenarios of the java collection framework

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report