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 the basic introduction of Set?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail what is the basic introduction of Set. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Architecture of Set

Set is an interface that inherits from Collection and is a collection that does not allow repeating elements.

AbstractSet is an abstract class, which inherits most of the functions in Set implemented by AbstractCollection,AbstractCollection, and provides convenience for the implementation class of Set.

The main implementation classes of Set are HashSet, LinkedHashSet, and TreeSet.

HashSet

The underlying layer is implemented through HashMap

No guarantee of any order of elements

Non-thread-safe, the element can be null

LinkedHashSet

The underlying layer is implemented through LinkedHashMap

Ensure the insertion order of elements

Non-thread safe, element cannot be null

TreeSet

The underlying layer is implemented through TreeMap

Sort elements using the natural order of elements

Non-thread safe, element cannot be null

Set source code parses public interface Set extends Collection {/ * * returns the number of elements in the collection * * / int size (); / * * returns whether the current collection is empty * * / boolean isEmpty (); / * * returns an Object array containing all the elements in the current collection * / Object [] toArray () / * * returns a specified type T array containing all elements in the current collection * * / T [] toArray (T [] a); / * * returns whether the current collection contains elements o * * / boolean contains (Object o); / * * returns whether the current collection contains all elements in the specified collection c * / boolean containsAll (Collection c) / * * add elements e * * / boolean add (E e) to the current collection; / * * add all elements in the specified collection c to the current collection * * / boolean addAll (Collection c); / * * keep only the elements that exist in both the current collection and the specified collection c * / boolean retainAll (Collection c) / * * remove all elements in the current collection * * / void clear (); / * * return the iterator of the current collection * * / Iterator iterator (); / * * return a divisible iterator to increase parallel processing power Inherited from the Iterable API; the new method of JDK1.8 * * / default Spliterator spliterator () {return Spliterators.spliterator (this, Spliterator.DISTINCT);}} this is the basic introduction to Set. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

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