List of usage examples for java.util LinkedHashMap clear
public void clear()
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); lHashMap.clear(); System.out.println(lHashMap.size()); }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); System.out.println(map);//from w w w .j a v a 2s. com // clear the map map.clear(); System.out.println(map); }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); System.out.println(map);/*from ww w .j av a2 s .c o m*/ // clear the map map.clear(); System.out.println(map); }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5, 0.75F); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); System.out.println(map);//www .j a va 2 s.c o m // clear the map map.clear(); System.out.println(map); }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5, 0.75F, true); // add some values in the map map.put("One", 1); map.put("Two", 2); map.put("Three", 3); System.out.println(map);//from w w w. jav a 2 s. c o m // clear the map map.clear(); System.out.println(map); }
From source file:Main.java
public static <K, V> void sortMap(LinkedHashMap<K, V> map, Comparator<Map.Entry<K, V>> c) { List<Map.Entry<K, V>> entries = new ArrayList<>(map.entrySet()); entries.sort(c);/*from w w w .j ava 2 s . c o m*/ map.clear(); for (Map.Entry<K, V> e : entries) { map.put(e.getKey(), e.getValue()); } }
From source file:Main.java
public static <K, V> void putAt(LinkedHashMap<K, V> map, K key, V value, int pos) { Iterator<Entry<K, V>> ei = map.entrySet().iterator(); LinkedHashMap<K, V> pre = new LinkedHashMap<>(); LinkedHashMap<K, V> post = new LinkedHashMap<>(); for (int i = 0; i < pos; i++) { if (!ei.hasNext()) break; Entry<K, V> tmpE = ei.next(); pre.put(tmpE.getKey(), tmpE.getValue()); }// w ww .j a v a 2 s .com // skip element at pos if (ei.hasNext()) ei.next(); while (ei.hasNext()) { Entry<K, V> tmpE = ei.next(); post.put(tmpE.getKey(), tmpE.getValue()); } map.clear(); map.putAll(pre); map.put(key, value); map.putAll(post); }
From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java
public void testClear() { LinkedHashMap<String, String> hashMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(hashMap); hashMap.put("Hello", "Bye"); assertFalse(hashMap.isEmpty());/* w w w. j a va 2 s .c o m*/ assertTrue(hashMap.size() == SIZE_ONE); hashMap.clear(); assertTrue(hashMap.isEmpty()); assertTrue(hashMap.size() == 0); }
From source file:com.opengamma.component.factory.engine.EngineConfigurationComponentFactory.java
@Override public void init(final ComponentRepository repo, final LinkedHashMap<String, String> configuration) { afterPropertiesSet();//from ww w . ja va2 s . c o m final Map<String, Object> map = new LinkedHashMap<String, Object>(); buildConfiguration(repo, configuration, map); final Map<String, Object> outer = new LinkedHashMap<String, Object>(); outer.put(DEFAULT_CONFIGURATION_DOCUMENT_ID, map); final DataConfigurationResource resource = new DataConfigurationResource(getFudgeContext(), outer); repo.getRestComponents().publishResource(resource); // indicate that all component configuration was used configuration.clear(); }
From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java
/** * Test method for 'java.util.LinkedHashMap.size()'. *///from w w w . ja va 2s . c o m public void testSize() { LinkedHashMap<String, String> hashMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(hashMap); // Test size behavior on put assertEquals(hashMap.size(), SIZE_ZERO); hashMap.put(KEY_1, VALUE_1); assertEquals(hashMap.size(), SIZE_ONE); hashMap.put(KEY_2, VALUE_2); assertEquals(hashMap.size(), SIZE_TWO); hashMap.put(KEY_3, VALUE_3); assertEquals(hashMap.size(), SIZE_THREE); // Test size behavior on remove hashMap.remove(KEY_1); assertEquals(hashMap.size(), SIZE_TWO); hashMap.remove(KEY_2); assertEquals(hashMap.size(), SIZE_ONE); hashMap.remove(KEY_3); assertEquals(hashMap.size(), SIZE_ZERO); // Test size behavior on putAll hashMap.put(KEY_1, VALUE_1); hashMap.put(KEY_2, VALUE_2); hashMap.put(KEY_3, VALUE_3); LinkedHashMap<String, String> srcMap = cloneLinkedHashMap(hashMap); hashMap.putAll(srcMap); assertEquals(hashMap.size(), SIZE_THREE); // Test size behavior on clear hashMap.clear(); assertEquals(hashMap.size(), SIZE_ZERO); }