Code Comments
Programming Forum and web based access to our favorite programming groups.What is the best way to sort an array of strings, by that i mean, sort each individual string alphabetically, and maybe then have two arrays, one with the sorted word and the other with the original word, so that they can be cross referenced. At the moment I am considering using mergesort, is this a good idea, or if there something more practical? I am writing a class which finds anagrams from a large set of words. Cheers Paul
Post Follow-up to this messageOn 28-10-2004 14:15, Paul Morrison wrote: > What is the best way to sort an array of strings, by that i mean, sort eac h > individual string alphabetically, and maybe then have two arrays, one with > the sorted word and the other with the original word, so that they can be > cross referenced. At the moment I am considering using mergesort, is this a > good idea, or if there something more practical? I am writing a class whic h > finds anagrams from a large set of words. > > Cheers > > Paul See the help on Arrays.sort(Object[] a). This might help you. Paul.
Post Follow-up to this message
"Paul Morrison" <pm42@kent.ac.uk> wrote in message
news:clqnt7$qbu$1@athena.ukc.ac.uk...
> What is the best way to sort an array of strings, by that i mean, sort
each
> individual string alphabetically, and maybe then have two arrays, one with
> the sorted word and the other with the original word, so that they can be
> cross referenced. At the moment I am considering using mergesort, is this
a
> good idea, or if there something more practical? I am writing a class
which
> finds anagrams from a large set of words.
>
If you mean sort array: {"bag", "ape", "can"}
to: {"abg", "aep", "acn"}
then iterate the array doing this on each element:
char[] chs = myString.toCharArray()
Arrays.sort(chs);
newArray[i] = new String(chs);
--
Mike W
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.