A HashMap isn't storing all of the entries.

S

Stryder

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.
 
S

Stryder

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.
 
D

Daniele Futtorovic

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.
 
L

Lew

Daniele said:
Stryder said:
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/

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.

PEBKAC.

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

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

Eric Sosman

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)
 
S

Stryder

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.

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 address removed)
 
L

Lew

Stryder said:
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. Shit or stay off the pot.
 
J

John B. Matthews

Stryder said:
]
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>
 
D

Daniele Futtorovic

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,
 
R

Roedy Green

Oooh! A value judgment
What is the matter with you Lew? You ALWAYS include a personal attack
along with your advice. What for? It is just a reflexive rudeness.

People have every right to be where they are. There was a time when
even you did not know everything. Should you too have been belittled
for being a beginner?

We are here to HELP beginners, to encourage them to become better
programmers, not to scare them off.

It is a very unbecoming trait. It is as though you constantly need to
stroke you own ego by finding excuses to put others down.

Perhaps your goal is to scare off new Java programmers. In that you
have been remarkably successful.
 
R

Roedy Green

Oooh! A value judgment!

If you were "helping" people face to face, and you said the things you
do routinely on the net, people would punch your lights out. You
simply would not do it. You are hiding behind the net to behave like
a jerk.
 
D

Daniel Pitts

If you were "helping" people face to face, and you said the things you
do routinely on the net, people would punch your lights out. You
simply would not do it. You are hiding behind the net to behave like
a jerk.
I'm not going to offer a judgement on whether or not Lew is rude. I
will point out however that he is usually helpful, which I can't say
about many pedants on usenet. In other newsgroups I've been lead down
the garden path by people ostensibly "helping" me. Lew is usually, if
nothing else, to the point and accurate.
 
A

Arne Vajhøj

What is the matter with you Lew? You ALWAYS include a personal attack
along with your advice. What for? It is just a reflexive rudeness.

If "Oooh! A value judgment" is considered a personal attack, then
I don't think that person is suited for usenet.

If you were referring to something else the quote it.
People have every right to be where they are. There was a time when
even you did not know everything. Should you too have been belittled
for being a beginner?

We are here to HELP beginners, to encourage them to become better
programmers, not to scare them off.

It is a very unbecoming trait. It is as though you constantly need to
stroke you own ego by finding excuses to put others down.

Perhaps your goal is to scare off new Java programmers. In that you
have been remarkably successful.

Lew can sometimes be a bit hard on beginners, but I did not see anything
in this thread.

Did you read it?

Arne
 
A

Arne Vajhøj

If you were "helping" people face to face, and you said the things you
do routinely on the net, people would punch your lights out. You
simply would not do it. You are hiding behind the net to behave like
a jerk.

Maybe.

Or maybe Lew is living in an environment where it is not
considered acceptable to use violence.

Just because you apparently accept violence in discussions
does not mean that it is accepted everywhere.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top