In this example we will show the common method to get the size of LinkedHashMap in Java.
Source Code
package com.beginner.examples;
import java.util.LinkedHashMap;
public class GetSizeOfLinkedHashMap {
public static void main(String[] args) {
//create LinkedHashMap.
LinkedHashMap linkedHashMap = new LinkedHashMap();
linkedHashMap.put("1","Alice");
linkedHashMap.put("2","Bob");
linkedHashMap.put("3","Jack");
/*
* To get the size of LinkedHashMap use size() method of LinkedHashMap.
*/
System.out.println("The size of LinkedHashMap is : " + linkedHashMap.size());
}
}
Output:
The size of LinkedHashMap is : 3
References
Imported packages in Java documentation: