View Full Version : hashSet order of elements
02-05-2010, 08:10 PM
HashSet hs1 = new HashSet();
How to make this work from 'plantae ?
02-05-2010, 08:40 PM
Don't use a HashSet. By definition, *any* kind of hash table WILL NOT store it's contents in alphabetical order.
If you want an ordered collection, use an ordered collection type. Period.
It's actually somewhat coincidental that you got the values in the order that you did. If you had tried a larger list of values, I'm sure they wouldn't have been that ordered.
Now...if you want "a" to come before "1", then you will have to also generate a custom comparator. But that still shouldn't work with HashSet.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.