ConcurrentSkipListSet first() method in Java Last Updated : 17 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The first() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the first (lowest) element currently in this set. Syntax: ConcurrentSkipListSet.first() Return Value: The function returns the first (lowest) element currently in this set. Exception: The function throws NoSuchElementException if this set is empty. Below programs illustrate the ConcurrentSkipListSet.first() method: Program 1: Java // Java Program Demonstrate first() // method of ConcurrentSkipListSet import java.util.concurrent.ConcurrentSkipListSet; class ConcurrentSkipListSetFirstExample1 { public static void main(String[] args) { // Initializing the set ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<Integer>(); // Adding elements to first set set.add(10); set.add(35); set.add(20); set.add(25); System.out.println("The lowest element in the set: " + set.first()); } } Output: The lowest element in the set: 10 Program 2: Program to show NoSuchElementException in first(). Java // Java Program Demonstrate first() // method of ConcurrentSkipListSet import java.util.concurrent.ConcurrentSkipListSet; class ConcurrentSkipListSetFirstExample2 { public static void main(String[] args) throws InterruptedException { // Initializing the set ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<Integer>(); try { System.out.println("The lowest element in the set: " + set.first()); } catch (Exception e) { System.out.println("Exception :" + e); } } } Output: Exception :java.util.NoSuchElementException Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#first-- Comment More infoAdvertise with us Next Article ConcurrentSkipListSet equals() method in Java R rupesh_rao Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ConcurrentSkipListSet +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ConcurrentSkipListSet floor() method in Java The floor() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the greatest element in this set less than or equal to the given element, or null if there is no such element. Syntax: ConcurrentSkipListSet.floor(E e) Parameter: The function accepts a sin 2 min read ConcurrentSkipListSet higher() method in Java The higher(E e) method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the least element in this set strictly greater than the given element, or null if there is no such element. Syntax: public E higher(E e) Parameter: The function accepts a single paramet 2 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 ConcurrentSkipListSet contains() method in Java The contains() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns a true boolean value if the specified element is present in this set otherwise it returns false. Syntax: ConcurrentSkipListSet.contains(Object o) Parameters: The function accepts a singl 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 add() method in Java The java.util.concurrent.ConcurrentSkipListSet.add() method is an in-built function in Java which is used to insert an element in this set. Syntax: ConcurrentSkipListSet.add(E e) Parameters: The function accepts a single parameter e i.e. the element to be inserted. Return Value: The function returns 2 min read Like