Home > Archive > Java Help > October 2004 > Sorting Strings
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Paul Morrison 2004-10-28, 8:58 am |
| 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
| |
| Paul H. van Rossem 2004-10-28, 8:58 am |
| On 28-10-2004 14:15, Paul Morrison wrote:
> 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
See the help on Arrays.sort(Object[] a). This might help you.
Paul.
| |
| VisionSet 2004-10-28, 8:58 am |
|
"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
|
|
|
|
|