Thursday, October 16, 2025
HomeLanguagesJavaConcurrentSkipListSet spliterator() method in Java

ConcurrentSkipListSet spliterator() method in Java

The java.util.concurrent.ConcurrentSkipListSet.spliterator() method is an in-built function in Java which returns a weakly uniform Spliterator across the elements of this set.

Syntax:

ConcurrentSkipListSet.spliterator()

Parameters: The function does not accept any parameter.

Return Value: The function returns a Spliterator across the elements of this set.

Below programs illustrate the ConcurrentSkipListSet.spliterator() method:

Program 1:




// Java Program Demonstrate Spliterator()
// method of ConcurrentSkipListSet
  
import java.util.Spliterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetSpliteratorExample1 {
    public static void main(String[] args)
    {
        // Initializing the set
        ConcurrentSkipListSet<String> set = 
                    new ConcurrentSkipListSet<String>();
  
        // Adding elements to this set
        set.add("Gfg");
        set.add("is");
        set.add("best!!");
  
        // spliterator split and iterate
        // the split parts in parallel
        Spliterator<String> str = set.spliterator();
  
        // performs the action for each remaining element
        str.forEachRemaining(
            (n) -> {
                String lc = n.toUpperCase();
                System.out.println(" Lower case = " + n);
                System.out.println(" Upper case = " + lc);
                System.out.println();
            });
    }
}


Output:

Lower case = Gfg
Upper case = GFG

Lower case = best!!
Upper case = BEST!!

Lower case = is
Upper case = IS

Program 2:




// Java Program Demonstrate Spliterator()
// method of ConcurrentSkipListSet
  
import java.util.Spliterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetSpliteratorExample2 {
    public static void main(String[] args)
    {
        // Initializing the set
        ConcurrentSkipListSet<Character> set = 
                         new ConcurrentSkipListSet<Character>();
  
        // Adding elements to this set
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            set.add(ch);
        }
  
        // Printing elements in the set
        System.out.print("The elements in the set are : ");
  
        // spliterator  split and iterate
        // the split parts in parallel
        Spliterator<Character> str = set.spliterator();
  
        // if element exists tryAdvance() will perform action
        while (str.tryAdvance((n) -> System.out.print(n + " ")))
            ;
    }
}


Output:

The elements in the set are : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#spliterator–

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS