[Novice to] How to learn Java collections

Preface

Only a bald head can become stronger.

The text has been included in my GitHub Featured Article, welcome to Star : https://github.com/ZhongFuCheng3y/3y

If you know my classmates, you might know that I have written many series of articles, but none of them are written for students who are just getting started . Most of them are written according to my personal learning progress.

image.png Series articles

Although you can read one by one in the order of my articles, if you are new to beginners, you may want to get a study guide (route guide). So I have this article, hoping to help students who are just getting started.

If the response to this article is good, we will continue to update other topics. I feel well written, hope you can give me a praise !

Java Collection Study Guide

This article will raise many questions that may be thought of by novices, but will not answer them one by one, and will only clarify the general direction. The content of this article is biased towards guides rather than technical tutorials.

If you want a specific answer, you can read the information I have written:

https://github.com/ZhongFuCheng3y/3y

Or join the talent exchange group to discuss with many developers. The previous Github link has my contact information.

Before learning a technology, you must know why you want to learn it!

Q: We have to know why we need to learn Java collections. When we learn Java collections, we have already learned arrays. Why do I use Java collections instead of arrays. What is the difference between an array and a Java collection?

image.png Learn Java collections first need to know

A: Java is an object-oriented language, it is inevitable to deal with objects, in order to facilitate the operation of multiple objects, then we have to store these multiple objects, if you want to store multiple objects (variables), it is easy to think of A container (collection) to load

In general: Java provides us with tools to facilitate us to manipulate multiple Java objects .

image.png Convenient operation of multiple objects

How to start learning Java collections

Q: From the above, we already know why we should learn Java collections. Below we should know the basic usage of Java collections and understand what it is from the overall knowledge points.

image.png Getting started with Java collections

A: We actually learn Java collections to facilitate the operation of multiple objects, and Java provides us with a series of APIs (methods) for us to operate. So when we first learn Java collections, we are more to learn what these APIs (methods) mean.

image.png API usage and effects

Q: After we have a certain understanding of the API usage of Java collections, we should understand it from an object-oriented perspective. Why are multiple interfaces abstracted, and what are the characteristics of each interface.

image.png To understand the interface and the common classes under each interface from an object-oriented perspective

A: We can summarize several commonly used implementation classes . For these commonly used implementation classes, we must know what their data structure is and when to use this class.

image.png Need to know the data structure of each common subclass

Data structure to learn and understand:

image.png data structure

At this point, after we briefly understand the data structure of each implementation class, we may simply remember the following conclusions :

  • If it is a collection type, there are List and Set for us to choose. List is characterized by orderly insertion and elements are repeatable. The characteristic of Set is that the insertion is disordered and the elements cannot be repeated. As for which implementation class to choose as our storage container, we have to look at the specific application scenario. If you want to be repeatable, you have to use List and select the common subcategories under List. It is hoped that it cannot be repeated, and select the common subclass under Set.

  • If it is a Key-Valuetype, then we will choose Map. If you want to keep the insertion order, we can choose LinkedHashMap, if you don't need it, choose HashMap, if you want to sort, choose TreeMap.

  • In short: After learning the data structure of common implementation classes, you will have a clear understanding of its usage scenarios.

image.png What kind of container to choose to store our objects, the key is to understand the data structure of each commonly used collection class

Assembly advancement and interview

If we know what kind of collection to choose as our container when we write code, then we are already getting started. But what you need to know is that if you go to the interview, you shouldn’t only know so little.

(If you are still a beginner or have a zero foundation , I suggest you can skip this part. There may be many comments on the Internet, such as: "If you have a solid Java foundation, then you will not worry about finding a job in the future. When you are learning Java basics You must learn the basics well and look at the source code!" But I think this piece is established when there is a certain coding/project or when you are looking for a job. If you are just starting to learn Java, you should not look at the source code. It’s easy to dissuade yourself )

My point is: If you are just starting to learn Java, you must first know exactly why you want to learn this, what is the use of this, where it is used, and familiarity with the commonly used methods is enough. Even if you spend about two weeks looking at the source code implementation, you may understand it. But believe me, you will probably forget it .

Java collection is the focus of the interview. During the interview, almost every company will ask collection questions, from basic to source code, step by step. The knowledge points of Java collection interview are not limited to basic usage. Maybe the interviewer will ask you:

  • What is the data structure of HashMap? How did he expand? Are red-black trees used in the bottom layer? How does the JDK source code implement the Key Hash value? Why do you want to do this?

  • Is HashMap thread safe? What is thread safety? What is a better solution? How is the thread-safe HashMap implemented?

  • How does HashSet determine that the Key is duplicated?

  • …..very many

image.png to sum up

If you want a specific answer, you can read the information I have written:

https://github.com/ZhongFuCheng3y/3y

Or join the talent exchange group to discuss with many developers, the previous article link has my contact information.

The original image of the mind map is also available on GitHub

At last

In general, it is not difficult to get started with Java collections. In the final analysis, I think there are three things:

  • Understand why you should learn Java collections

  • Learn the various interfaces of the Java collection and the commonly used implementation class usage

  • Learn what the data structure of commonly used implementation classes are, and choose a suitable implementation class to load your own objects when writing code.

There is no need to read the source code for the zero-based entry, and you must review and read the source code before the interview (this is a must-test knowledge point for the interview)!

image.png This article summarizes
Welcome to the exchange group learning, notes plus group to tell the truth in this group, even if you do not speak, just look chats, can learn somethingimage

image.png


Guess you like

Origin blog.51cto.com/15082392/2590290