In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what HashSet refers to. It is concise and easy to understand. It will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
HashSet is a collection that does not allow you to store repeating elements, and its implementation is relatively simple, as long as you understand HashMap,HashSet.
Member variable
First, take a look at the member variables of HashSet:
Private transient HashMap map
/ / Dummy value to associate with an Object in the backing Map
Private static final Object PRESENT = new Object ()
There are only two main variables found:
* map: used to store the final data.
* RESENT: is all value values written to map.
Constructor public HashSet () {
Map = new HashMap ()
}
Public HashSet (int initialCapacity, float loadFactor) {
Map = new HashMap (initialCapacity, loadFactor)
}
The constructor is simple, initializing map with HashMap.
Add public boolean add (E e) {
Return map.put (e, PRESENT) = = null
}
The key is the add () method. You can see that it treats the stored object as the key to the HashMap, and the value is all the same PRESENT. Because the key of HashMap cannot be repeated, every time a duplicate value is written to HashSet, value will be overwritten, but key will not be affected, thus ensuring that only non-repeating elements can be stored in HashSet.
The principle of HashSet is relatively simple, almost all with the help of HashMap. Therefore, the problems that will occur in HashMap can not be avoided by HashSet.
What does HashSet refer to above? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.