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
}
Aggregations