Saturday, July 4, 2026
HomeLanguagesJavaConcurrentSkipListMap size() method in Java with Examples

ConcurrentSkipListMap size() method in Java with Examples

The size() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which that is it returns the number of keys mapped to this map. The size() method is not a constant time operation. In case the map contains more than Integer.MAX_VALUE elements, the maximum value of the map is returned.

Syntax:

public int size()

Parameter: The function does not accepts any parameters.

Return Value: The function returns the number of elements in this map.

Below programs illustrate the above method:

Program 1:




// Java Program Demonstrate size()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer,
                                            Integer>();
  
        // Adding elements to this map
        for (int i = 1; i <= 5; i++)
            mpp.put(i, i);
  
        // print size of map
        System.out.println(mpp.size());
    }
}


Output:

5

Program 2:




// Java Program Demonstrate size()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer,
                                            Integer>();
  
        // Adding elements to this map
        for (int i = 1; i <= 15; i++)
            mpp.put(i, i);
  
        // print size of map
        System.out.println(mpp.size());
    }
}


Output:

15

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS