Sorting arraylist objects by alpha

Okay i have my arraylist and other methods created.

Now, i need sort my arraylist objects by their alphabetical field, and then print them.

The toString i already have handled.

Does anyone know of a SIMPLE sorting method i can use to sort my array objects by alphabetical, so that i can redisplay them in alphabetical order instead of item number?

[372 byte] By [Zerofurya] at [2007-11-27 9:20:12]
# 1
What would be really neat, is if i can get them to list just the item name, and only reorder them by alpha without ruining their counter position.
Zerofurya at 2007-7-12 22:13:08 > top of Java-index,Java Essentials,Java Programming...
# 2

Use the Collections.sort() method. There are two of them: the one you want is the one that has a Comparator argument.

This Comparator is the thing that allows you to specify how the sort should take place. In your case you will need to make a comparator that takes two of your objects and returns a value based on the string comparison of the relevant fields.

The Collections API is here: http://java.sun.com/javase/6/docs/api/java/util/Collections.html

JavaWorld has a nice article discussing the problem here: http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

pbrockway2a at 2007-7-12 22:13:08 > top of Java-index,Java Essentials,Java Programming...
# 3
That Javaworld article is quite nice. Thanks pbrockway2
petes1234a at 2007-7-12 22:13:08 > top of Java-index,Java Essentials,Java Programming...