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

Introduction and use of TreeSet

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

Share

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

This article mainly introduces "introduction and use of TreeSet". In daily operation, I believe many people have doubts about the introduction and use of TreeSet. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "introduction and use of TreeSet"! Next, please follow the editor to study!

Introduction to TreeSet public class MyTreeSet extends AbstractSet implements NavigableSet, Cloneable, Serializable {}

TreeSet inherits the AbstractSet abstract class and implements the NavigableSet interface, which is an ordered collection based on TreeMap implementation and supports natural sorting or Comparator sorting provided.

About NavigableSet public interface NavigableSet extends SortedSet {/ * * returns the largest element less than the given element e, or NULL if not. * * / E lower (E e); / * * returns the largest element that is less than or equal to the given element e, or NULL if not. * * / E floor (E e); / * * returns the smallest element greater than or equal to the given element e, or NULL if not. * * / E ceiling (E e); / * * returns the smallest element greater than the given element e, or NULL if not. * * / E higher (E e); / * retrieve and delete the first smallest element, and return NULL if not. * * / E pollFirst (); / * retrieve and delete the last largest element, and return NULL if not. * * / E pollLast (); / * * the element between fromElement and toElement can be set whether to contain fromElement and toElement * * / NavigableSet subSet (E fromElement, boolean fromInclusive, E toElement, boolean toInclusive); / * * the element before returning toElement can be set whether to contain toElement element * / NavigableSet headSet (E toElement, boolean inclusive) / * * the element after returning fromElement can be set to contain fromElement element * * / NavigableSet tailSet (E fromElement, boolean inclusive); / * * the element between fromElement and toElement contains fromElement but does not contain toElement * * / SortedSet subSet (E fromElement, E toElement); / * * the element before toElement does not contain toElement element * / SortedSet headSet (E toElement) / * * the element returned after fromElement contains fromElement element * * / SortedSet tailSet (E fromElement);}

The NavigableSet interface inherits the SortedSet interface, and the last three interfaces inherit from SortedSet

About SortedSet public interface SortedSet extends Set {/ * * returns the comparator * * / Comparator cc = set.comparator (); Comparator e = m.pollFirstEntry (); return e = = null? Null: e.getKey ();} public E pollLast () {Map.Entry e = m.pollLastEntry (); return e = = null? Null: e.getKey ();} public Iterator iterator () {return m.navigableKeySet (). Iterator ();} public NavigableSet descendingSet () {return m.descendingKeySet ();} public Iterator descendingIterator () {return m.navigableKeySet () .descendingIterator ();} public NavigableSet subSet (E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) {return new TreeSet (fromElement, fromInclusive, toElement, toInclusive) } public NavigableSet headSet (E toElement, boolean inclusive) {return new TreeSet (m.headMap (toElement, inclusive));} public NavigableSet tailSet (E fromElement, boolean inclusive) {return new TreeSet (m.tailMap (fromElement, inclusive));} at this point, the study on "introduction and use of TreeSet" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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