JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: How to iterate through LinkedHashMap?


Description:

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


Code:
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));
		}
	}
}

Output:
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
StringBuffer Vs StringBuilder
The only difference between StringBuffer and StringBuilder is StringBuffer is thread-safe, that is StringBuffer is synchronized.
Famous Quotations
The very best thing you can do for the whole world is to make the most of yourself.
-- Wallace Wattles

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 © 2022 by Nataraja Gootooru. All Rights Reserved.