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

[1235 byte] By [RAM@SUNa] at [2007-11-26 18:23:18]
# 1
The example you are looking at is worthless. Take the collection tutorial, instead: http://java.sun.com/docs/books/tutorial/collections/index.html
DrLaszloJamfa at 2007-7-9 5:57:11 > top of Java-index,Java Essentials,Java Programming...
# 2

Did you try running your program? It's usually an easy and acceptable way of getting closer to what it does. You may add som System.out.println() calls or run it in your debugger to get more information.

From reading through it quickly, it seems to me that your understanding is (roughly) correct in (a), (b) and (c), but I don't think you end up with a null in (d), rather with a reference to an empty HashMap. Like yourself and the previous poster, I cannot see that this program could be used for anything in real life.

OleVVa at 2007-7-9 5:57:11 > top of Java-index,Java Essentials,Java Programming...