A HashMap isn't storing all of the entries.

Discussion in 'Java' started by Stryder, Dec 5, 2012.

  1. Stryder

    Stryder Guest

    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.
    Stryder, Dec 5, 2012
    #1
    1. Advertising

  2. Stryder

    Stryder Guest

    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.
    Stryder, Dec 5, 2012
    #2
    1. Advertising

  3. 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.
    Daniele Futtorovic, Dec 5, 2012
    #3
  4. Stryder

    Lew Guest

    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
    Lew, Dec 6, 2012
    #4
  5. Stryder

    Eric Sosman Guest

    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
    d
    Eric Sosman, Dec 6, 2012
    #5
  6. Stryder

    Stryder Guest

    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
    >
    > d
    Stryder, Dec 6, 2012
    #6
  7. Stryder

    Lew Guest

    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. Shit or stay off the pot.

    --
    Lew
    Lew, Dec 6, 2012
    #7
  8. In article <>,
    Stryder <> 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>
    John B. Matthews, Dec 6, 2012
    #8
  9. 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.
    Daniele Futtorovic, Dec 7, 2012
    #9
  10. Stryder

    Eric Sosman Guest

    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
    d
    Eric Sosman, Dec 7, 2012
    #10
  11. Stryder

    Roedy Green Guest

    On Thu, 6 Dec 2012 10:54:06 -0800 (PST), Lew <>
    wrote, quoted or indirectly quoted someone who said :

    >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.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    Students who hire or con others to do their homework are as foolish
    as couch potatoes who hire others to go to the gym for them.
    Roedy Green, Dec 8, 2012
    #11
  12. Stryder

    Roedy Green Guest

    On Thu, 6 Dec 2012 10:54:06 -0800 (PST), Lew <>
    wrote, quoted or indirectly quoted someone who said :

    >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.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    Students who hire or con others to do their homework are as foolish
    as couch potatoes who hire others to go to the gym for them.
    Roedy Green, Dec 8, 2012
    #12
  13. Stryder

    Daniel Pitts Guest

    On 12/8/12 2:10 AM, Roedy Green wrote:
    > On Thu, 6 Dec 2012 10:54:06 -0800 (PST), Lew <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >> 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.

    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.
    Daniel Pitts, Dec 10, 2012
    #13
  14. Stryder

    Arne Vajhøj Guest

    On 12/8/2012 4:01 AM, Roedy Green wrote:
    > On Thu, 6 Dec 2012 10:54:06 -0800 (PST), Lew <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >> 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.


    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
    Arne Vajhøj, Dec 10, 2012
    #14
  15. Stryder

    Arne Vajhøj Guest

    On 12/8/2012 5:10 AM, Roedy Green wrote:
    > On Thu, 6 Dec 2012 10:54:06 -0800 (PST), Lew <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >> 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.


    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
    Arne Vajhøj, Dec 10, 2012
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vince Darley
    Replies:
    4
    Views:
    4,411
    emilchacko
    Mar 2, 2010
  2. Robert Bj?rn
    Replies:
    0
    Views:
    419
    Robert Bj?rn
    Jun 1, 2004
  3. John Nagle
    Replies:
    4
    Views:
    590
    James Antill
    Aug 7, 2007
  4. Rakesh
    Replies:
    10
    Views:
    12,167
    Mike Schilling
    Apr 8, 2008
  5. Don Bruder
    Replies:
    3
    Views:
    964
    spikeysnack
    Aug 3, 2010
Loading...

Share This Page