The ConcurrentSkipListSet extends the abstract class AbstractSet and implements the NavigableSet interface. ConcurrentSkipListSet is a part of Java collection framework and is available in java.util package. Implementation of the NavigableSet makes this class to keep the elements sorted order (Set kept elements sorted in their natural order or by a comparator provided at the time of creation of set). This class is useful when you require safely execution of the operations insert, remove and access concurrently by the multiple threads at a time. This class doesn't allow 'null' elements because the 'null' arguments and values can't be distinguished from the absence of elements.
Java collection framework - ConcurrentSkipListSet
The ConcurrentSkipListSet extends the abstract class AbstractSet and implements the NavigableSet interface. ConcurrentSkipListSet is a part of Java collection framework and is available in java.util package. Implementation of the NavigableSet makes this class to keep the elements sorted order (Set kept elements sorted in their natural order or by a comparator provided at the time of creation of set). This class is useful when you require safely execution of the operations insert, remove and access concurrently by the multiple threads at a time. This class doesn't allow 'null' elements because the 'null' arguments and values can't be distinguished from the absence of elements.
Syntax
public class ConcurrentSkipListSet<E> extends AbstractSet<E> implements NavigableSet<E>
Constructor of ConcurrentSkipListSet
This class provides constructor for constructing new sets according to requirement :
ConcurrentSkipListSet() : It makes a new vacate set into which the elements are ordered according to their natural order.
ConcurrentSkipListSet(Collection<? extends E> c) : It makes a set that contains the elements of a defined collection into which its elements are arranged in their natural order.
ConcurrentSkipListSet(Comparator<? super E> comparator) : It makes a new vacate set into which the elements are ordered according to the defined comparator.
ConcurrentSkipListSet(SortedSet<E> s) : It makes a new set that contains the elements and follows their order like the defined set.
Methods of ConcurrentSkipListSet
This class provides various methods some of them are :
- add()
- ceiling()
- floor()
- last()
- lower()
syntax : public boolean add(E e)
syntax : public E ceiling(E e)
syntax : public E floor(E e)
syntax : public E last()
syntax : public E lower(E e)
Example
package devmanuals.com; import java.util.concurrent.ConcurrentSkipListSet; import java.util.Set; class ConcurrentSkipListSetDemo { public static void main(String[] args) { ConcurrentSkipListSet cl = new ConcurrentSkipListSet(); for(double i=1; i<=10; i++){ i=i+ 0.5; cl.add(i); } System.out.println("Elements are "+cl); System.out.println("Floor "+cl.floor(4.0)); System.out.println("Ceiling "+cl.ceiling(3.5)); System.out.println("Lower "+cl.lower(10.0)); System.out.println("heigher "+cl.higher(5.0)); System.out.println("Head Elements "); Set clHeadView = cl.headSet(5.0); System.out.println(clHeadView); System.out.println("Tail Elements "); Set clTailView = cl.tailSet(5.0); System.out.println(clTailView); } }
Output :
Elements are [1.5, 3.0, 4.5, 6.0, 7.5, 9.0, 10.5] Floor 3.0 Ceiling 4.5 Lower 9.0 heigher 6.0 Head Elements [1.5, 3.0, 4.5] Tail Elements [6.0, 7.5, 9.0, 10.5] |
[ 0 ] Comments