import java.util.*;
public class HashMapImp {
public static void main(String[] args) {
//If we take key as object
//Then key can be any datatype
Map<Object,Object> hMap=new HashMap<Object,Object>();
hMap.put(1, 1);
hMap.put(2, 3.0);
hMap.put(3.0, "Hello");
hMap.put(1, 2);
hMap.put("Abhi", 1);
System.out.println(hMap);
//Map contains Integer as key
//And String as value
Map<Integer,String> map=new HashMap<Integer,String>();
map.put(1, "Hi");
map.put(2, "Abhi");
map.put(3, "Hello");
map.put(1, "I");
map.put(3,"Abhi");
System.out.println(map);
}
}
public class HashMapImp {
public static void main(String[] args) {
//If we take key as object
//Then key can be any datatype
Map<Object,Object> hMap=new HashMap<Object,Object>();
hMap.put(1, 1);
hMap.put(2, 3.0);
hMap.put(3.0, "Hello");
hMap.put(1, 2);
hMap.put("Abhi", 1);
System.out.println(hMap);
//Map contains Integer as key
//And String as value
Map<Integer,String> map=new HashMap<Integer,String>();
map.put(1, "Hi");
map.put(2, "Abhi");
map.put(3, "Hello");
map.put(1, "I");
map.put(3,"Abhi");
System.out.println(map);
}
}
0 comments:
Post a Comment