Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20129

Re: A HashMap isn't storing all of the entries.

Received by 10.68.202.68 with SMTP id kg4mr43929pbc.3.1354752312947; Wed, 05 Dec 2012 16:05:12 -0800 (PST)
Received by 10.50.33.137 with SMTP id r9mr1434205igi.8.1354752312907; Wed, 05 Dec 2012 16:05:12 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!kr7no10188121pbb.0!news-out.google.com!s9ni29189pbb.0!nntp.google.com!kr7no10188117pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Wed, 5 Dec 2012 16:05:12 -0800 (PST)
In-Reply-To <k9omh1$maq$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
NNTP-Posting-Host 69.28.149.29
References <1c2ba883-7e16-4312-90dc-8d87f52bfd05@googlegroups.com> <k9omh1$maq$1@dont-email.me>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <89ea7a9d-58bc-4a98-9f41-085baa50b32d@googlegroups.com> (permalink)
Subject Re: A HashMap isn't storing all of the entries.
From Lew <lewbloch@gmail.com>
Injection-Date Thu, 06 Dec 2012 00:05:12 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.java.programmer:20129

Show key headers only | View raw


Daniele Futtorovic wrote:
> Stryder allegedly wrote:
>> I'm doing this...
>> 
>>         HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);

Why do you declare it with an initial capacity of 5? That seems strikingly pointless.

Why do you declare the variable as 'HashMap' rather than 'Map'?

>>         devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
>>         devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
>>         devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
>>         devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"});
>>         devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});
>> 
>> but it's dropping the first entry.

Wrong. It's not doing that. You are.

> I'll bet 50� that it isn't actually dropping it, or that the reason for
> it lies in code residing outside of the java.* hierarchy.

I wouldn't take that bet, because you're almost certainly correct.

We won't know exactly where the problem is until the OP deigns to provide a 
http://sscce.org/

>> I got it to work by increasing the initial number of entries in the HashMap constructor, 

Wrong again. Also, why 5? What's wrong with 16?

By starting the map at 5 buckets and giving it 5 entries, you guaranteed at least one 
growth cycle for the map. The load factor by default is 0.75, so you really should have at least 
8 buckets for 5 entries.

You do realize that 'HashMap' increases size automatically, right, and it doesn't drop 
entries when it does so? Your data loss has nothing to do with the initial capacity of the 
map.

>> so the question is pretty much academic unless I encounter it again. 
>> But I'd be interested if anyone knows the answer. 

PEBKAC.

Give us an SSCCE or give up on knowing what you did wrong.

By the way, 'devObjectMap' is a very unsatisfactory variable name.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

A HashMap isn't storing all of the entries. Stryder <stryder100@gmail.com> - 2012-12-05 15:29 -0800
  Re: A HashMap isn't storing all of the entries. Stryder <stryder100@gmail.com> - 2012-12-05 15:37 -0800
    Re: A HashMap isn't storing all of the entries. "John B. Matthews" <nospam@nospam.invalid> - 2012-12-06 14:22 -0500
  Re: A HashMap isn't storing all of the entries. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-06 00:48 +0100
    Re: A HashMap isn't storing all of the entries. Lew <lewbloch@gmail.com> - 2012-12-05 16:05 -0800
  Re: A HashMap isn't storing all of the entries. Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-05 21:07 -0500
    Re: A HashMap isn't storing all of the entries. Stryder <stryder100@gmail.com> - 2012-12-06 05:09 -0800
      Re: A HashMap isn't storing all of the entries. Lew <lewbloch@gmail.com> - 2012-12-06 10:54 -0800
        Re: A HashMap isn't storing all of the entries. Roedy Green <see_website@mindprod.com.invalid> - 2012-12-08 01:01 -0800
          Re: A HashMap isn't storing all of the entries. Arne Vajhøj <arne@vajhoej.dk> - 2012-12-10 15:32 -0500
        Re: A HashMap isn't storing all of the entries. Roedy Green <see_website@mindprod.com.invalid> - 2012-12-08 02:10 -0800
          Re: A HashMap isn't storing all of the entries. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-10 09:33 -0800
          Re: A HashMap isn't storing all of the entries. Arne Vajhøj <arne@vajhoej.dk> - 2012-12-10 15:35 -0500
      Re: A HashMap isn't storing all of the entries. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-07 03:50 +0100
        Re: A HashMap isn't storing all of the entries. Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-06 23:46 -0500

csiph-web