Thursday, June 11, 2026
HomeLanguagesJavaConcurrentSkipListSet size() method in Java

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 elements in the queue.

Below programs illustrate the ConcurrentSkipListSet.size() method:

Program 1:




// Java Program Demonstrate size()
// method of ConcurrentSkipListSet
  
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetSizeExample1 {
    public static void main(String[] args)
    {
        // Initializing the set
        ConcurrentSkipListSet<Integer> set = 
                       new ConcurrentSkipListSet<Integer>();
  
        // Adding elements to this set
        for (int i = 1; i <= 10; i++)
            set.add(i);
  
        // Printing the size of the set
        System.out.println("Number of elements in the set = "
                           + set.size());
        // Printing the elements
        System.out.println("set : " + set);
    }
}


Output:

Number of elements in the set = 10
set : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Program 2:




// Java Program Demonstrate size()
// method of ConcurrentSkipListSet
  
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetSizeExample2 {
    public static void main(String[] args)
    {
        // Initializing the set
        ConcurrentSkipListSet<String> set = 
                         new ConcurrentSkipListSet<String>();
  
        // Adding elements to this set
        set.add("A");
        set.add("B");
        set.add("C");
        set.add("D");
        set.add("E");
  
        // Printing the size of the set
        System.out.println("Number of elements in the set = "
                           + set.size());
        // Printing the elements
        System.out.println("set : " + set);
    }
}


Output:

Number of elements in the set = 5
set : [A, B, C, D, E]

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS