ConcurrentSkipListSet subSet() method in Java with Examples Last Updated : 17 Nov, 2021 Comments Improve Suggest changes Like Article Like Report The subSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java where the elements are returned in a range defined by this method. The syntax of the function gives a clear understanding of the specified element followed by the examples.Syntax: subSet(E fromElement, E toElement) or subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) Parameters: The first variation of this method takes two parameters, which defines the range of elements that are going to be returned. The toElement is not included in the returned set.The second variation is similar to first one but here the boolean parameters specifically include or exclude the toElement and fromElement. Returns: The first method variation returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. The second method variation returns a view of the portion of this set whose elements range from fromElement to toElements as defined by the boolean inclusive parameter.Exception: Null Pointer Exception: if the specified elements are NULL.Below are the sample programs to illustrate ConcurrentSkipListSet subSet() in Java:Example: 1 The elements from 30000 to 90000 are returned, but 90000 is excluded. Java // Java program to demonstrate ConcurrentSkipListSet subSet() method import java.util.concurrent.ConcurrentSkipListSet; class ConcurrentSkipListSetExample { public static void main(String[] args) { // Initializing the set using ConcurrentSkipListSet() ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set set.add(65552); set.add(34324); set.add(93423); set.add(41523); set.add(90000); // Printing the ConcurrentSkipListSet System.out.println("ConcurrentSkipListSet: " + set); // Printing the elements of ConcurrentSkipListSet that // are returned by subSet() method System.out.println("The returned elements are: " + set.subSet(30000, 90000)); } } Output: ConcurrentSkipListSet: [34324, 41523, 65552, 90000, 93423] The returned elements are: [34324, 41523, 65552] Example: 2 In this example, element 400 is also returned because boolean inclusive is true. Java // Java program to demonstrate ConcurrentSkipListSet subSet() method import java.util.concurrent.ConcurrentSkipListSet; class ConcurrentSkipListSetExample { public static void main(String[] args) { // Initializing the set using ConcurrentSkipListSet() ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set set.add(652); set.add(324); set.add(400); set.add(123); set.add(200); // Printing the ConcurrentSkipListSet System.out.println("ConcurrentSkipListSet: " + set); // Printing the elements of ConcurrentSkipListSet that // are returned by subSet() method System.out.println("The returned elements are: " + set.subSet(100, true, 400, true)); } } Output: ConcurrentSkipListSet: [123, 200, 324, 400, 652] The returned elements are: [123, 200, 324, 400] Comment More infoAdvertise with us Next Article ConcurrentSkipListSet subSet() method in Java with Examples P ProgrammerAnvesh Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-ConcurrentSkipListSet +1 More Practice Tags : JavaJava-Collections Similar Reads ConcurrentSkipListSet tailSet() method in Java with Examples The tailSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java where the elements which are equal to or greater than the specified element are returned. The syntax of the function gives a clear understanding of the specified element followed by the examples.Syntax 2 min read ConcurrentSkipListSet lower() method in Java with Examples The lower() method of ConcurrentSkipListSet is used to return the largest element present in this set which is strictly less than the specified element. If there is no such element present in the set, then this function will return null. Syntax: public E lower (E e) Parameters: This method takes onl 2 min read ConcurrentSkipListSet subSet() method in Java subSet(E fromElement, E toElement) The subSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the 5 min read ConcurrentSkipListSet comparator() method in Java with Examples The comparator() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the comparator used for ordering the elements in the given set. If natural ordering is used, null is returned. Syntax: public Comparator<E> comparator() Here E is the type parame 2 min read ConcurrentSkipListSet equals() method in Java The equals() method of java.util.concurrent.ConcurrentSkipListSet is an inbuilt function in Java which compares the specified object with this set for equality. It returns True if the specified object is also a set. The two sets will said to be equal if they satisfies all of the conditions stated be 3 min read ConcurrentSkipListSet size() method in Java The java.util.concurrent.ConcurrentSkipListSet.size() method is an in-built function in Java which gives the total count of the elements present in the set. Syntax: ConcurrentSkipListSet.size() Parameters: The function does not accept any parameter. Return Value: The function returns the number of e 2 min read ConcurrentHashMap entrySet() method in Java with Examples The entrySet() method of ConcurrentHashMap in Java is used to create a set from the same elements contained in the concurrent hash map. It basically returns a set view of the concurrent hash map or we can create a new set and store the map elements into them. Syntax: ConcurrentHashMap.entrySet() Par 2 min read Set contains() method in Java with Examples The Java.util.Set.contains() method is used to check whether a specific element is present in the Set or not. So basically it is used to check if a Set contains any particular element. Syntax: boolean contains(Object element) Parameters: The parameter element is of the type of Set. This is the eleme 2 min read ConcurrentSkipListMap in Java with Examples The ConcurrentSkipListMap class is a member of the Java Collections Framework. It was introduced in JDK 1.6, it belongs to java.util.concurrent package. The ConcurrentSkipListMap is a scalable implementation of ConcurrentNavigableMap. All the elements are sorted based on natural ordering or by the C 10 min read ConcurrentSkipListSet headSet() method in Java headSet(E toElement) The java.util.concurrent.ConcurrentSkipListSet.headSet() method is an in-built function in Java which returns a view of the portion of this set whose elements are strictly less than toElement. The returned set is backed by this set, so changes in the returned set are reflected i 4 min read Like