Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 16 October 2016

What is SortedSet Interface In Java ?

Previously we have discussed about

Here we learn What is SortedSet interface in Java.But Before That you must Know What is Collection Interface in Java ?
Interface SortedSet<E>

Type Parameters:
E - the type of elements maintained by this set

All Superinterfaces:
Collection<E>, Iterable<E>, Set<E>

All Known Subinterfaces:

All Known Implementing Classes:
ConcurrentSkipListSet, TreeSet

Declaration of SortedSet:
public interface SortedSet<E>
extends Set<E>

A SortedSet is a Set that maintains its elements in ascending order i.e natural order or according to a comparator provided at creation time.

SortedSet defines several methods that make Set processing more convenient. To obtain the first object in the Set, call first( ). To get the last element, use last( ). You can obtain a subset of a sorted Set by calling subSet( ),If you need the subset that starts with the first element in the Set, use headSet( ). If you want the subset that ends the Set, use tailSet( ).

Several methods of SortedSet throw NoSuchElementException when no items are contained in set.
It also throw ClassCastException when an object is incompatible with elements of set.A NullPointerException is also thrown if an attempt is made to use null object in set.
This interface is a member of the Java Collections Framework.

Method Summary of SortedSet:

Modifier and Method Name
Description
Comparator<? super E> comparator()
Returns the comparator used to order the elements in this set, or null if this set uses the natural ordering of its elements.
E first()
Returns the first (lowest) element currently in this set.
SortedSet<E> headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly less than toElement.
E last()
Returns the last (highest) element currently in this set.
SortedSet<E> subSet(E fromElement, E toElement)
Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
SortedSet<E> tailSet(E fromElement)
Returns a view of the portion of this set whose elements are greater than or equal to fromElement.

      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment