A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Apr 11, 2002
Jun 02, 2002 03:41:00
public static void main(
Integer a = new Integer(4);
Integer b = new Integer(8);
Integer c = new Integer(4);
hs = new
the running result of it is[8,4] why not [4,8]? how can I enforce the result as [4,8]?
Joined: Jun 11, 2001
Jun 02, 2002 04:07:00
Weiliu, you're getting unexpected result because hash set does not guarantee the order of its elements because it's based on hashing. If you want to enforce the results, you can use
I agree. Here's the link:
Q on collections framework: iteration order
Question on HashSet & LinkedHashSet
A simple Hash Map Example.
Why this block of code behave differently..?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014