Functionality of HashMap
Hi Guys
When i trying to haspmap from the online. i got this source code. I got some doubts in this can you guys please explain me the concept
[CODE]
HashMap gMap1 = new HashMap();
HashMap gMap2 = new HashMap();
if(gMap1.get("Cigar")==null)
gMap1.put("Cigar",new HashMap());
gMap2 = (HashMap) gMap1.get("Cigar");
[/CODE]
If my explanation is wrong please help me to understand the Concept
a) In the line 1 and Line 2 he created two haspmaps
b) In the Line 3 he is checking that gmap1(HashMap) got the Value for the Object Cigar(key). My question How can he check Because the Map is just created and it is empty.It has no keys. Where he got that object/key from?. In the Line 4 he is putting the Object. How can he check for that key/object before he is putting into the map
c) In the line 4 he is putting the Cigar object and with the value as newHashMap(). So is he creating new hashmap object as a value.If yes what is the use of doing that.
d) In the Last line he is putting that value in the Second Map that is gmap2 so it means the that gmap2 contains null Value .
Am i Confusing with my little Java Knowledge.
Thanks
Ram

