Create LinkedHashMap and loop through it - Java Collection Framework

Java examples for Collection Framework:LinkedHashMap

Description

Create LinkedHashMap and loop through it

Demo Code



import java.util.LinkedHashMap;
import java.util.Map;

public class LinkedHashMapTest
{
    private void testIterator()
    {//from  ww w  .ja  v  a2  s. c o  m
        System.out.println("--testIterator--");
        String k1 = "b2";
        String k2 = "aQ";
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put(k1, "v1");
        map.put(k2, "v2");
        map.put("k3", "v3");
        map.put("k4", "v4");
        map.put("k5", "v5");
        for (Map.Entry<String, String> entry : map.entrySet())
        {
            System.out.println(entry.getKey());
        }
    }
    
    public static void main(String[] args)
    {
        LinkedHashMapTest test = new LinkedHashMapTest();
        test.testIterator();
    }
    
}

Related Tutorials