- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Add elements to LinkedHashMap collection in Java
Use the put() method to add elements to LinkedHashMap collection.
First, let us create a LinkedHashMap −
LinkedHashMap<String, String> l = new LinkedHashMap<String, String>();
Now, add elements −
l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");
The following is an example to add elements to LinkedHashMap collection −
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); } }
Output
LinkedHashMap elements {1=Jack, 2=Tom, 3=Jimmy, 4=Morgan, 5=Tim, 6=Brad}
- Related Articles
- Add all the elements from a collection to the HashSet in Java
- Java Program to Compare Elements in a Collection
- Add elements to HashMap in Java
- Add elements to HashSet in Java
- LinkedHashMap and LinkedHashSet in Java
- Rotate elements of a collection in Java
- Retrieving Elements from Collection in Java- Iterator
- Retrieving Elements from Collection in Java- ListIterator
- Retrieving Elements from Collection in Java- EnumerationIterator
- How to add elements in Java CopyOnWriteArrayList?
- How to add elements in Java ArrayBlockingQueue?
- Add elements to a Vector in Java
- Append all elements of other Collection to ArrayList in Java
- Java Program to Shuffle the Elements of a Collection
- Get Size of Java LinkedHashMap

Advertisements