@@ -0,0 +1,2707 @@
+package com.lance.practise.algorithm.cache;%0A%0Aimport java.util.LinkedHashMap;%0Aimport java.util.Map;%0A%0A/**%0A * @author Shenglan Wang%0A */%0Apublic class MapExample %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        Map%3CString, String%3E map = new LinkedHashMap%3C%3E(16, 0.75f, true);%0A%0A        map.put(%221%22, %2211%22);%0A        map.put(%222%22, %2222%22);%0A        map.put(%223%22, %2233%22);%0A//        map.get(%222%22);%0A        map.put(%222%22, %2222%22);%0A%0A        for (Map.Entry%3CString, String%3E entry : map.entrySet()) %7B%0A            System.out.println(entry.getKey() + %22 : %22 + entry.getValue());%0A        %7D%0A%0A        for (String key : map.keySet()) %7B%0A            System.out.println(key + %22 : %22 + map.get(key));%0A        %7D%0A%0A%0A        // Map representing (Company, share price) as (key, value) pair%0A        Map%3CString, Double%3E linkedHashMap = new LinkedHashMap%3CString, Double%3E();%0A        linkedHashMap.put(%22Apple%22, new Double(91.98));%0A        linkedHashMap.put(%22Sony%22, new Double(16.76));%0A        linkedHashMap.put(%22Dell%22, new Double(30.47));%0A        linkedHashMap.put(%22HP%22, new Double(33.91));%0A        linkedHashMap.put(%22IBM%22, new Double(181.71));%0A%0A        // Displaying the contents of the LinkedHashMap%0A        System.out.println(%22Contents of LinkedHashMap : %22 + linkedHashMap);%0A%0A        // One of the ways of iterating over the map%0A        // Notice the order of the elements is same as the order of insertion%0A        System.out.println(%22%5CnValues of map after iterating over it : %22);%0A        for (String key : linkedHashMap.keySet()) %7B%0A            System.out.println(key + %22:%5Ct%22 + linkedHashMap.get(key));%0A        %7D%0A%0A        // Getting the value for a particular key%0A        System.out.println(%22%5CnThe current share price of HP is : %22%0A                + linkedHashMap.get(%22HP%22));%0A%0A        // Getting the size of the LinkedHashMap%0A        System.out%0A                .println(%22%5CnThe size of the LinkedHashMap is : %22 + linkedHashMap.size());%0A%0A        // Checking whether the LinkedHashMap is empty%0A        System.out.println(%22%5CnIs LinkedHashMap empty? : %22 + linkedHashMap.isEmpty());%0A%0A        //Checking whether Map contains a particular key or value%0A        System.out.println(%22%5CnLinkedHashMap contains Sony as key? : %22 + linkedHashMap.containsKey(%22Sony%22));%0A        System.out.println(%22LinkedHashMap contains 999.0 as value? : %22 + linkedHashMap.containsValue(999.0));%0A%0A        // Removing a particular value%0A        System.out.println(%22%5CnRemove entry for Dell : %22 + linkedHashMap.remove(%22Dell%22));%0A        System.out.println(%22Content of LinkedHashMap removing Dell: %22 + linkedHashMap);%0A%0A        // Clearing the LinkedHashMap%0A        linkedHashMap.clear();%0A        System.out.println(%22%5CnContent of LinkedHashMap after clearing: %22 + linkedHashMap);%0A    %7D%0A%7D%0A

Add LinkedHashMap Example