The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util  [50 examples] > Hash Tables  [3 examples]

e356. Creating a Map That Retains Order-of-Insertion

    Map map = new LinkedHashMap();
    
    // Add some elements
    map.put("1", "value1");
    map.put("2", "value2");
    map.put("3", "value3");
    map.put("2", "value4");
    
    // List the entries
    for (Iterator it=map.keySet().iterator(); it.hasNext(); ) {
        Object key = it.next();
        Object value = map.get(key);
    }
    // [1=value1, 2=value4, 3=value3]

 Related Examples
e355. Creating a Hash Table
e357. Automatically Removing an Unreferenced Element from a Hash Table

See also: Arrays    Bits    Collections    Dates    Lists    Property Files    Sets    Sorted Collections    Time    Timers   


© 2002 Addison-Wesley.