Java HashMap size() method example

HQ ┬╗ Java Tutorial ┬╗ java.util ┬╗ Hashmap ┬╗ size() method example
Java HashMap size() method example 2018-02-16T07:27:22+00:00

java.util.HashMap size()

Description :

On this document we will be showing a java example on how to use the size() method. Basically this method just return how many key-value combination in our HashMap. This method might be useful in situation wherein we have to determine the size of our HashMap before performing business operations. Important notes for size method:

  • specified by size in interface Map<K,V>
  • overrides┬ásize in class AbstractMap<K,V>

Method Syntax :

public int size()

Parameter Input :

[table] DataType|Parameter|Description
N/A|N/A|N/A[/table]

Method Returns :

The size method returns the number of key-value mappings in this map.

Compatibility Version :

Requires Java 1.2 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of size() method of HashMap class.

Sample Output :

Running the above java example of the usage of HashMap method will give the following output:

HashHamp size method example

HashHamp size method example output

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close