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

How to use Java Collection HashSet,TreeSet and LinkedHashSet

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to use Java collection HashSet,TreeSet and LinkedHashSet". 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!

HashSet defines public class HashSet extends AbstractSet implements Set, Cloneable, java.io.Serializable

HashSet inherits the AbstractSet class and implements the Set, Cloneable, and Serializable interfaces. AbstractSet provides the backbone implementation of the Set interface, thus minimizing the work required to implement this interface. The = = Set interface is a Collection that does not include repeating elements, and it maintains its own internal ordering, so random access makes no sense. = =

This article carries on the source code analysis based on 1.8jdk.

Basic attribute

Based on HashMap implementation, the underlying layer uses HashMap to save all elements

Private transient HashMap map;// defines an Object object as the valueprivate static final Object PRESENT = new Object () of HashMap

Constructor function

/ * * default constructor * initializes an empty HashMap with a default initial capacity of 16 and a load factor of 0.75. * / public HashSet () {map = new HashMap ();} / * constructs a new set that contains the elements in the specified collection. * / public HashSet (Collection

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

Development

Wechat

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

12
Report