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 is Set in Java

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you what Set is in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Overview of Set

Because the structure and implementation of Set are highly consistent with Map, it will no longer be analyzed here, and interested friends can check the source code for themselves. But we still need to know what Set,Set is a collection of non-repeatable elements, that is, all elements are unique. Take a look at the documentation:

A collection that contains no duplicate elements. More formally, sets contain no pair of elements E1 and e2 such that e1.equals (E2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

In addition, the Set series also has sorting-based interfaces such as SortedSet and NavigableSet, and their functions have been introduced in detail in the analysis of Map.

Summary

After analyzing the source code of so many collection classes, the biggest feeling is not "Oh, so it is", but amazed at the author's highly abstract thinking, rigorous code, and extremely standard coding style. The value of the code itself is far less than the benefits of this idea, and we should master these principles instead of remembering boring code implementations.

But behind the surprise, the hardship paid by the author is also enormous, which is also full of bitterness and helplessness. The purpose of creating so many data structures is to improve the ability to process data. However, the reality is that if we want to pursue the extreme on the one hand, we must make compromises in other aspects, and there is no structure that can enable us to do so once and for all. So the demand is endless and the exploration is endless. Do you remember the query method in LinkedList? At such a small point, I tried my best to increase the query speed by half. At that time, I was really amazed by this operation, on the one hand, because of the delicacy of the engineer, on the other hand, it may be because of the exclamation, "Hey, I really can't do more."

In the collection class of Java, a large number of equals, hashCode, clone methods depend on the object, and some of them require us to implement the Comparable interface. If you have an understanding of the data structure and know which data structures are used by the collection class, I think it can be inferred which methods need to be implemented. If we can grasp these details, we can write better code. If we can master these ideas, we can get rid of the shackles of language and understand the essence of software design.

The above is all the content of this article "what is Set in Java?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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