Java HashMap size() Method
Example
Get the size of a map:
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities.put("England", "London");
capitalCities.put("Germany", "Berlin");
capitalCities.put("Norway", "Oslo");
capitalCities.put("USA", "Washington DC");
System.out.println(capitalCities.size());
}
}
Definition and Usage
The size()
method returns the number of entries in a map.
Syntax
public int size()
Technical Details
Returns: | The number of entries in the map. |
---|
Related Pages
❮ HashMap Methods