By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Sorting arrays of multiple fields

P: n/a
Hi,

I have an array of object Anag containing a string and a list of other
strings (anagram dictionary). That is, some records in the array may only
have two fields (anagram and the one word that matches it), where as others
may have three or more (i.e. elmno, melon, lemon).

Is there any way to sort this array alphabetically by the first field?
Arrays.sort only seems to work for arrays of strings...

Cheersm

Darryl
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SMC
On Mon, 01 Dec 2003 14:43:52 +1100, Darryl Woodford wrote:
Hi,

I have an array of object Anag containing a string and a list of other
strings (anagram dictionary). That is, some records in the array may
only have two fields (anagram and the one word that matches it), where
as others may have three or more (i.e. elmno, melon, lemon).

Is there any way to sort this array alphabetically by the first field?
Arrays.sort only seems to work for arrays of strings...

Cheersm

Darryl


Look at implementing your own Comparator object

http://java.sun.com/j2se/1.4.2/docs/...omparator.html

which you can pass to Arrays.sort to tell it how to inspect and order
your array. It's easier than it looks. Google for examples.

--
Sean

"There are 10 types of people in this world, those who can count in binary,
and those who can't."
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.