harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Meschberger <fmesc...@gmail.com>
Subject Re: [classlib][luni] HDK's HashSet returns the element in different order compare to RI
Date Fri, 21 Aug 2009 05:33:54 GMT

The JavaDoc of java.util.HashSet says:

   "It makes no guarantees as to the iteration order
   of the set; in particular, it does not guarantee
   that the order will remain constant over time."

So, both RI and HDK are correct according to the JavaDoc (and to my
understanding of Sets being unordered collections).

Testing sets using their string representations will almost certainly
fail sooner or later even on the same JDK version but on different
platforms !


Mohanraj Loganathan schrieb:
> When i run the testcase[1] i am getting the different output with RI and
> HDK. Any thoughts on this.
> I dont find anything specific to the order for HashSet mentioned in the
> spec.
> RI prints : [c, b, e, d]
> HDK prints : [b, c, d, e]
> HDK prints in Character order. But not sure in what order RI prints. One of
> the Maven unit test depicts the same scenario, and it fails with HDK.
> [1] Test
>     public void test_HashSet() {
>         HashSet hashSet = new HashSet();
>         hashSet.add("b");
>         hashSet.add("e");
>         hashSet.add("c");
>         hashSet.add("d");
>         System.out.println(hashSet);
>     }
> Thanks and Regards.
> Mohan

View raw message