Search in sources :

Example 46 with AbstractMap

use of java.util.AbstractMap in project Note-Java by ianlai.

the class HashMapUse method main.

public static void main(String[] args) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    map.put("dog", 1);
    map.put("cat", 1);
    map.put("lion", 1);
    map.put("fish", 1);
    // null
    System.out.println(map.get("iii"));
    /* Use iterator to iterate the map */
    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        System.out.println(pair.getKey() + " --- " + pair.getValue());
        System.out.println(pair.getKey().getClass().getName() + " --- " + pair.getValue().getClass().getName());
    }
    add("aa bb ccc dddd ee", "ccc bb ee");
    // ------------------------------------------
    /* We initiate a map with a concrete class */
    Map<Integer, Integer> mp1 = new HashMap<>();
// Map<Integer, Integer> mp2 = new Map<>();                        //Map is an interface
// Map<Integer, Integer> mp2 = new AbstractMap<Integer,Integer>(); //AbstractMap is an abstract class
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) AbstractMap(java.util.AbstractMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AbstractMap (java.util.AbstractMap)46 HashMap (java.util.HashMap)27 Map (java.util.Map)20 IdentityHashMap (java.util.IdentityHashMap)19 LinkedHashMap (java.util.LinkedHashMap)19 TreeMap (java.util.TreeMap)17 WeakHashMap (java.util.WeakHashMap)13 Collection (java.util.Collection)8 Set (java.util.Set)7 InputStream (java.io.InputStream)4 SequenceInputStream (java.io.SequenceInputStream)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ReadResult (io.pravega.segmentstore.contracts.ReadResult)2 IOException (java.io.IOException)2 Cleanup (lombok.Cleanup)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 IndexSettings (org.elasticsearch.index.IndexSettings)2