Map<String, Integer> map = new HashMap<>();
Map <Integer, Point2D.Double> hm = new HashMap<Integer, Point2D>();
hm.put(1, new Point2D.Double(50, 50));
Map<Integer,String> map=new HashMap<>();
map.put(1,"john");
map.put(2,"kale");
for(Map.Entry<Integer,String> x:map.entrySet()){
System.out.println(x.getKey());
System.out.println(x.getValue());
}
MAP : is a (key-value format)
and keys are always unique,
and value can be duplicated.
- HashTable don't have null key, sychronized(thread-safe)
- LinkedHashMap can have null key, keeps order
- HasHMap can have null key, order is not guaranteed
- TreeMap doesn't have null key and keys are sorted
// Map implementation using HashMap
Map<Key, Value> numbers = new HashMap<>();
Map <Integer, Point2D.Double> hm = new HashMap<Integer, Point2D>();
hm.put(1, new Point2D.Double(50, 50));