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<>();