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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

5

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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());
    }
}

chevron_right


Output:

15

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

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.