You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Nicholoz Koka Kiknadze <ki...@gmail.com> on 2008/07/04 14:19:12 UTC

Result HashMap elemnt order

Hi,

I get results using resultClass="java.util.HashMap" and I expected that if I
iterate values of the HashMap the order will correspond to the order in my
fields. However it does not. Is that normal behavior?

In other words I have 'Select f1, f2, f3 from Blah', and iterating in the
HashMap values I get something like f2,f1,f3

iBatis version 2.3.0.677.

Tya

Re: Result HashMap elemnt order

Posted by Nicholoz Koka Kiknadze <ki...@gmail.com>.
Aaah, many thanks, so I think I'd better try with  LinkedHashMap. Will test
it in the evening.


On Fri, Jul 4, 2008 at 4:56 PM, Larry Meadors <la...@gmail.com>
wrote:

> Maps in Java are not ordered.
>
>    public static void main(String[] args) {
>        Map m = new HashMap();
>        m.put("this", "this");
>        m.put("is", "is");
>        m.put("a", "a");
>        m.put("test", "test");
>        for(Object o:m.values()) System.out.println(o);
>    }
>
> The output on my box is:
>
> a
> is
> this
> test
>
> Larry
>
>
> On Fri, Jul 4, 2008 at 6:19 AM, Nicholoz Koka Kiknadze
> <ki...@gmail.com> wrote:
> > Hi,
> >
> > I get results using resultClass="java.util.HashMap" and I expected that
> if I
> > iterate values of the HashMap the order will correspond to the order in
> my
> > fields. However it does not. Is that normal behavior?
> >
> > In other words I have 'Select f1, f2, f3 from Blah', and iterating in the
> > HashMap values I get something like f2,f1,f3
> >
> > iBatis version 2.3.0.677.
> >
> > Tya
> >
> >
>

Re: Result HashMap elemnt order

Posted by Larry Meadors <la...@gmail.com>.
Maps in Java are not ordered.

    public static void main(String[] args) {
        Map m = new HashMap();
        m.put("this", "this");
        m.put("is", "is");
        m.put("a", "a");
        m.put("test", "test");
        for(Object o:m.values()) System.out.println(o);
    }

The output on my box is:

a
is
this
test

Larry


On Fri, Jul 4, 2008 at 6:19 AM, Nicholoz Koka Kiknadze
<ki...@gmail.com> wrote:
> Hi,
>
> I get results using resultClass="java.util.HashMap" and I expected that if I
> iterate values of the HashMap the order will correspond to the order in my
> fields. However it does not. Is that normal behavior?
>
> In other words I have 'Select f1, f2, f3 from Blah', and iterating in the
> HashMap values I get something like f2,f1,f3
>
> iBatis version 2.3.0.677.
>
> Tya
>
>

Re: Result HashMap elemnt order

Posted by Larry Meadors <la...@gmail.com>.
Neils FTW: The same code with that map type produces this output:

this
is
a
test

Cool trick!

Larry


On Fri, Jul 4, 2008 at 7:05 AM, Niels Beekman <n....@wis.nl> wrote:
> Use java.util.LinkedHashMap

RE: Result HashMap elemnt order

Posted by Niels Beekman <n....@wis.nl>.
Use java.util.LinkedHashMap

 

________________________________

From: Nicholoz Koka Kiknadze [mailto:kiknadze@gmail.com] 
Sent: Friday, July 04, 2008 2:19 PM
To: user-java@ibatis.apache.org
Subject: Result HashMap elemnt order

 

Hi,

I get results using resultClass="java.util.HashMap" and I expected that
if I iterate values of the HashMap the order will correspond to the
order in my fields. However it does not. Is that normal behavior?

In other words I have 'Select f1, f2, f3 from Blah', and iterating in
the HashMap values I get something like f2,f1,f3 

iBatis version 2.3.0.677.

Tya