freelanceprogrammers.org Forum Index » Java
Re: Sorting array alphabetically
Joined: 31 Jan 2002
Posts: 26
Re: Sorting array alphabetically
I did discover Arrays.sort() earlier, but now I`m
trying to figure out how to do it manually, using some
kind of sorting algorithm. (I confess it`s for an
assignment...)<br><br>I suppose you`d have to compare chars numerically,
but wouldn`t that get terribly complicated to get a
whole word into alphabetical order, not to mention
initials?! <br><br>Also, I need to include other data in the
output. I guess you`d have to make a person object. Would
you have to sort the whole object, but only on the
name and initial fields? Is this possible?
Joined: 31 Jan 2002
Posts: 26
Re: Sorting array alphabetically
I`ve got so far as making an array of "person"
objects, and I`ve done a bubble sort on it, using the
numerical value of the first char of the surname. That`s a
start. <br><br>The only thing I can think of to do now,
would be to count up all the names starting with "A"
etc, then sort those on the second char. And so on.
With a string that`s 15 chars long (with initials at
the end), that method seems to be rediculously
complicated. Could I be missing anything simpler...?
Joined: 02 Feb 2002
Posts: 4
Re: Sorting array alphabetically
You don`t have to search on the 1st letter, then
search those again on the 2nd letter. Use the
compareTo() method of the String class in your search
algorithm. This compares two Strings and will allow you to
put them in order.
Joined: 31 Jan 2002
Posts: 26
Re: Sorting array alphabetically
Thanks! It works now, and I expect that was all that was meant...
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







