a) In the line 1 and Line 2 he created two haspmaps
yes.
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
Line 3, is checking to see if a value exist with a particular key. You are right, in that the hashmap is empty, so the value that is returned should be null.
You can check for whatever key that you want, and at any time. If that functionality was not allowed, then how would you ever know if the key/value pair exist?
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.
You can use any object as the value. (You can also use any object as the key, but it would be a good idea to use non-changing objects as keys.)
As for what use of putting a hashmap in a hashmap, now that would depend on your program?
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
Actually no. In this line, he is changing the reference of gmap2 to refer to the object that is returned, from the gmap1 map, using the "Cigar" key. This should be the hashmap that was created in line 4.
Henry