AbstactMap.size()
in Java is a method of the AbstractMap
class. The method is used to get the key-value mappings in a map.
public int size()
The AbstactMap.size()
method takes in no parameters.
The AbstactMap.size()
method returns the size of the key-value mappings in the map.
If the map has more than
Integer.MAX_VALUE element
, then the method returnsInteger.MAX_VALUE
.
import java.util.*; public class Abstract_Map_Class{ public static void main(String[] args) { AbstractMap<Integer, String> temp_absMap = new TreeMap<Integer, String>(); int size = temp_absMap.size(); System.out.println("The size of the map is " + temp_absMap.size()); temp_absMap.put(1, "Hello"); temp_absMap.put(2, "from"); temp_absMap.put(3, "Educative"); System.out.println("Mapping is : " + temp_absMap); size = temp_absMap.size(); System.out.println("The size of the map is " + temp_absMap.size()); } }
First, create temp_absMap
, an empty AbstractMap
class object.
Then use the AbstractMap.size()
method to check the size of temp_absMap
and store it in the variable size
.
Next, use println()
to display the size of the temp_absmap
.
Then temp_absmap
by mapping string
values to int
keys.
Use println()
again to display the temp_absmap
.
Next, use the AbstractMap.size()
method again to store the size of the temp_absmap
after it has key-value pairs mapping stored in it.
Lastly, we use println()
to display the size of the temp_absmap
.
RELATED TAGS
CONTRIBUTOR
View all Courses