🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1373

Re: HashMap replacing entries

#1373
From: Greg Hamer
Date: Thu, 07 Feb 2002 17:36
41 lines
2644 bytes
One of your 'facts' is a bad assumption. As the keys are Strings, they will
certainly have different hashcodes. Why do you believe that the fourth one
is
replacing the second one? If  you place a parameterList.get("productIds")
immediately after the code you presented, you are definately going to get
back the productIds value. If you call parameterList.size(), it will return
5.
If you looking at the Hashmap in the debugger, you do see only 3 'buckets'
with values and the  bucket #9  has the 'productIds' key  which is where the
'statusIds' key used to be. But that does not mean that 'statusIds' has been
replaced, and that the Hashmap is broken. There are bajillions of possible
hashcodes, and HashMap maps them into 11 buckets by default. 'statusIds' and
'productIds' happen to be sharing a bucket. Look at the value for  bucket
#9's 'next' variable and you will see 'statusId' happily sitting there, not
lost at all.

"Andrew van der Voort" <andrew@astarte.co.nz> wrote in message
news:3c5f384b$1_1@dnews...
> Hi. I am building a HashMap of parameters to pass to a report generator.
>
> I add the following entries to the HashMap:
>
> HashMap parameterList = new HasMap();
> parameterList.put("severityCodes", severityCodes);
> parameterList.put("statusIds", statusIds);
> parameterList.put("typeIds", typeIds);
> parameterList.put("productIds", productIds);
> parameterList.put("assignedToIds", assignedToIds);
>
> where the values are String objects with some comma delimited numbers.
> The first three puts work fine, but the fourth put replaces the second
> entry, and the fifth put replaces the first entry.
>
> I have verified that the hashCodes generated by the 5 keys result in
> different values. What's going on?
>
> Thanks
>
> Andrew
>
>
Technical Details
Message-ID: <3c62bb2a$1_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!skynet.be!skynet.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3c5f384b$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,89a2c159d63ecd88
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-02-07 09:39:22 PST
From: "Greg Hamer" <ghamer@troikanetworks.com>
Newsgroups: borland.public.jbuilder.java.api
References: <3c5f384b$1_1@dnews>
Subject: Re: HashMap replacing entries
Date: Thu, 7 Feb 2002 09:36:10 -0800
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 12.31.172.108
Message-ID: <3c62bb2a$1_2@dnews>
X-Trace: dnews 1013103402 12.31.172.108 (7 Feb 2002 09:36:42 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!skynet.be!skynet.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews