VOOZH about

URL: https://www.geeksforgeeks.org/java/map-size-method-in-java-with-examples/

⇱ Map size() Method in Java With Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Map size() Method in Java With Examples

Last Updated : 15 Jul, 2025

Map size() method in Java is used to get the total number entries i.e, key-value pair. So this method is useful when you want total entries present on the map. If the map contains more than Integer.MAX_VALUE elements returnInteger.MAX_VALUE

Syntax:

int size();

Parameter: This method does not take any parameter.

Return value: This method returns the number of key-value mappings in this map.

Example 1: For non-generic input


Output:

Size of the map is : 4

Example 2: For Generic Input


Output:

Size of the map is : 4
Comment