Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > A HashMap isn't storing all of the entries.

Reply
Thread Tools

A HashMap isn't storing all of the entries.

 
 
Stryder
Guest
Posts: n/a
 
      12-05-2012
I'm doing this...

HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
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. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...

java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

Any help is appreciated. Thanks.
 
Reply With Quote
 
 
 
 
Stryder
Guest
Posts: n/a
 
      12-05-2012
On Wednesday, December 5, 2012 6:29:23 PM UTC-5, Stryder wrote:
> I'm doing this...
>
>
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
>
> 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. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...
>
>
>
> java version "1.7.0_03"
>
> Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
>
> Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
>
>
>
> Any help is appreciated. Thanks.


I got it to work by increasing the initial number of entries in the HashMap constructor, so the question is pretty much academic unless I encounter it again. But I'd be interested if anyone knows the answer.
 
Reply With Quote
 
 
 
 
Daniele Futtorovic
Guest
Posts: n/a
 
      12-05-2012
On 06/12/2012 00:29, Stryder allegedly wrote:
> I'm doing this...
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
> 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.


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.

--
DF.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-06-2012
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 atleast one
growth cycle for the map. The load factor by default is 0.75, so you reallyshould 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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-06-2012
On 12/5/2012 6:29 PM, Stryder wrote:
> I'm doing this...
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
> 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. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...


Your "verification" is wrong, with 99.44% probability. Could you
provide an SSCCE? Here's mine:

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Foo {
public static void main(String[] unused) {
HashMap<String, String[]> devObjectMap = new HashMap<String,
String[]>(5);
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"});

for (Map.Entry<String, String[]> me : devObjectMap.entrySet()) {
System.out.printf("\"%s\" -> %s%n", me.getKey(),
Arrays.toString(me.getValue()));
}
}
}

.... and the output is:

run:
"ContentArea" -> [All_Subject_Lines, Date_issue]
"DataExtension" -> [ADLN_Customer, ADLN_Story]
"EmailSendDefinition" -> [ADLN, AILR]
"Email" -> [ADLN, DRLN]
"ImportDefinition" -> [ADLN_Customer, ADLN_Story, AILR_Customer]
BUILD SUCCESSFUL (total time: 0 seconds)

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
Stryder
Guest
Posts: n/a
 
      12-06-2012
Thanks for your help, Eric, my verification was wrong. Lew, rude as he was, was correct, it was a dumb mistake on my part. That being said, this is my first intro to SSCCE, a valuable concept.

On Wednesday, December 5, 2012 9:07:13 PM UTC-5, Eric Sosman wrote:
> On 12/5/2012 6:29 PM, Stryder wrote:
>
> > I'm doing this...

>
> >

>
> > HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);

>
> > 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. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...

>
>
>
> Your "verification" is wrong, with 99.44% probability. Could you
>
> provide an SSCCE? Here's mine:
>
>
>
> import java.util.Arrays;
>
> import java.util.HashMap;
>
> import java.util.Map;
>
> public class Foo {
>
> public static void main(String[] unused) {
>
> HashMap<String, String[]> devObjectMap = new HashMap<String,
>
> String[]>(5);
>
> 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"});
>
>
>
> for (Map.Entry<String, String[]> me : devObjectMap.entrySet()) {
>
> System.out.printf("\"%s\" -> %s%n", me.getKey(),
>
> Arrays.toString(me.getValue()));
>
> }
>
> }
>
> }
>
>
>
> ... and the output is:
>
>
>
> run:
>
> "ContentArea" -> [All_Subject_Lines, Date_issue]
>
> "DataExtension" -> [ADLN_Customer, ADLN_Story]
>
> "EmailSendDefinition" -> [ADLN, AILR]
>
> "Email" -> [ADLN, DRLN]
>
> "ImportDefinition" -> [ADLN_Customer, ADLN_Story, AILR_Customer]
>
> BUILD SUCCESSFUL (total time: 0 seconds)
>
>
>
> --
>
> Eric Sosman
>
> (E-Mail Removed)d

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-06-2012
Stryder wrote:
> Thanks for your help, Eric, my verification was wrong. Lew, rude as he was, was correct,


Oooh! A value judgment!

You point me to anything I told you that was not strictly factually correct and
in any way denigrated you, and I'll grant you your off-point accusation.

Your code indicated that you had not thoroughly (granting you a lot) read
the Javadocs for map implementations.

This is a "teach a person to fish" arena. I hope for your sake you don't fall into
the trap of whining when things aren't fed you on a silver spoon with fawning,
obsequious fooferol to make it more palatable. **** or stay off the pot.

--
Lew
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      12-06-2012
In article <(E-Mail Removed)>,
Stryder <(E-Mail Removed)> wrote:

> On Wednesday, December 5, 2012 6:29:23 PM UTC-5, Stryder wrote:
> [...]
> I got it to work by increasing the initial number of entries in the
> HashMap constructor, so the question is pretty much academic unless I
> encounter it again. But I'd be interested if anyone knows the answer.


If the problem abated after reducing latency in growing the Map, one
might suspect a data race. If your Map is used to construct a Swing
component model, for example, you should rule out this common fault:

<http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      12-07-2012
On 06/12/2012 14:09, Stryder allegedly wrote:
>> Your "verification" is wrong, with 99.44% probability.
>>

> Thanks for your help, Eric, my verification was wrong. (...) it was a dumb mistake on my part.


Dammit! Couldn't you have show just a bit more pig-headedness and taken
my bet?! ;o)

For your edification, my (serious) willingness to bet didn't arise from
some blind faith in teh Jav, but rather from experience, that is from
the numerous cases where I, too, thought teh Jav was failing me, only to
make the humbling realisation that it was actually my very own failing.
I'll venture to say that Eric's 99.44% number came from similar sources.

PS: on Usenet, it is common to post your replies /below/ that to which
you respond to.

Cheers,

--
DF.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-07-2012
On 12/6/2012 9:50 PM, Daniele Futtorovic wrote:
> [...]
> I'll venture to say that Eric's 99.44% number came from similar sources.


Specifically, <http://tinyurl.com/b8uedkt>.

87.3% of quoted statistics are made up out of thin air.

For politicians, it's 103.6%.

--
Eric Sosman
(E-Mail Removed)d
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
User Images: Storing in Files VS Storing in Database Jonathan Wood ASP .Net 1 06-02-2008 05:56 PM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM
storing pointer vs storing object toton C++ 11 10-13-2006 11:08 AM
HashMap Sanjay Kumar Java 2 07-05-2003 07:10 PM



Advertisments