import java.util.*; public class LinkedHashMapDemo { public static void main(String[] args) { LinkedHashMap<String, Integer> hm = new LinkedHashMap<>(); hm.put("Anand", 20); hm.put("Mary", 20); hm.put("Ravi", 21); hm.put("John",19); System.out.println("Contents: "+hm); System.out.println(); Set<String> keys = hm.keySet(); for(String k: keys) System.out.println(k+" -- "+hm.get(k)); System.out.println(); Set<Map.Entry<String, Integer>> entries = hm.entrySet(); for(Map.Entry<String,Integer> each: entries) System.out.println(each.getKey()+" -- "+each.getValue()); System.out.println(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter