- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Size of Java LinkedHashMap
The size() method is used to get the size of LinkedHashMap in Java.
Create a LinkedHashMap and add some elements to it −
LinkedHashMap<String,String> l = new LinkedHashMap<String,String>(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");
Get the size now −
l.size()
The following is an example to get the size of LinkedHashMap −
Example
import java.util.LinkedHashMap; public class Demo { public static void main(String[] args) { LinkedHashMap<String,String> l = new LinkedHashMap<String,String>(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad"); System.out.println("LinkedHashMap elements: "+l); System.out.println("Size = "+l.size()); } }
Output
LinkedHashMap elements: {1=Jack, 2=Tom, 3=Jimmy, 4=Morgan, 5=Tim, 6=Brad} Size = 6
- Related Articles
- Get Size of Java LinkedHashSet
- Get size of HashSet in Java
- Get Size of TreeSet in Java
- Iterate through the values of Java LinkedHashMap in Java
- LinkedHashMap and LinkedHashSet in Java
- Get the size of an ArrayList in Java
- Get the size of the IdentityHashMap in Java
- Remove a value from Java LinkedHashMap
- Remove all values from Java LinkedHashMap
- Get the size of the LabelValue Tuple in Java
- Java Program to Get the Size of the Collection
- Add elements to LinkedHashMap collection in Java
- Difference Between HashMap and LinkedHashMap in Java
- Get JFrame window size information in Java
- Difference between TreeMap, HashMap, and LinkedHashMap in Java

Advertisements