Publish Your Article Here

Program: How to iterate through LinkedHashMap?


This example show how to iterate through LinkedHashMap. You always get elements by its insertion order.

package com.java2novice.linkedhashmap;

import java.util.LinkedHashMap;
import java.util.Set;

public class MyMapIterate {

        public static void main(String a[]){
                LinkedHashMap<String, String> lhm = new LinkedHashMap<String, String>();
                lhm.put("one", "This is first element");
                lhm.put("two", "This is second element");
                lhm.put("four", "Element inserted at 3rd position");
                Set<String> keys = lhm.keySet();
                for(String k:keys){
                        System.out.println(k+" -- "+lhm.get(k));

one -- This is first element
two -- This is second element
four -- Element inserted at 3rd position
<< Previous Program | Next Program >>

List Of All LinkedHashMap Sample Programs:

  1. LinkedHashMap basic operations
  2. How to iterate through LinkedHashMap?
  3. How to check whether the value exists or not in a LinkedHashMap?
  4. How to delete all entries from LinkedHashMap object?
  5. How to eliminate duplicate user defined objects as a key from LinkedHashMap?
  6. How to find user defined objects as a key from LinkedHashMap?
  7. How to delete user defined objects as a key from LinkedHashMap?
Knowledge Centre
Class, Constructor and Primitive data types
Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
Famous Quotations
Tomorrow is often the busiest day of the week.
-- Spanish Proverb

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2024 by Nataraja Gootooru. All Rights Reserved.