Code example for LinkedHashMap

Methods: clonekeySetputget

public class OldLinkedHashMapTest extends TestCase {
    public void testLinkedHashMap() { 
        // we want to test the LinkedHashMap in access ordering mode. 
        LinkedHashMap map = new LinkedHashMap<String, String>(10, 0.75f, true);
        map.put("key1", "value1");
        map.put("key2", "value2");
        map.put("key3", "value3");
        Iterator iterator = map.keySet().iterator();
        String id = (String);
        try { 
            // A LinkedHashMap is supposed to throw this Exception when a 
            // Operation takes place after a get 
            // Operation. This is because the get Operation is considered 
            // a structural modification if the LinkedHashMap is in 
            // access order mode. 
            fail("expected ConcurrentModificationException was not thrown.");
        } catch(ConcurrentModificationException expected) {
        LinkedHashMap mapClone = (LinkedHashMap) map.clone();
        iterator = map.keySet().iterator();
        id = (String);
        try { 
            new LinkedHashMap<String, String>(-10, 0.75f, true);
            fail("IllegalArgumentException expected");
Contextual code suggestions in your IDE  Get Codota for Java