My first time confusion about Map :
- Map is a interface not a class, so we can't create a Object of Map.
- Map are quite different from List , they contains key - value pair.
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class TestClass implements Map<String,String>{
public static void main(String ...strings){
Map<String,String> map = new HashMap<String,String>();
map.put("1" , "first");
map.put("2", "second");
map.put("2", null); Map can't have duplicate elements last value override previous value.
map.put(null, null); Key and Value both can be null.
System.out.println(map);
System.out.println(map.size());
}
}
Output :
{null=null, 2=null, 1=first}
3