File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Alphabetizing an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Alphabetizing an ArrayList" Watch "Alphabetizing an ArrayList" New topic

Alphabetizing an ArrayList

J. Floyd

Joined: Apr 27, 2010
Posts: 5

I am trying to alphabetize the contents of an arrayList by last name. I am completely stuck. Each element in the arrayList contains a string for first name, last name, address, city, state, zip, phone, fax. There are also two optional strings for cell and email.

Here is my code:

The program is not working. I commented out the Collections line and kept getting this as my output: [[Ljava.lang.Object;@13d93f4].

Any help would be greatly appreciated.

Thank you.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2454
You need to create a custom Object to store the individual properties. Then you can use a Comparator to sort on a specific property. Something like:

Sorting People by Name

Or you may find the Bean Comparator helpfull since you won't have to write a custom Comparator.
J. Floyd

Joined: Apr 27, 2010
Posts: 5
Thank you. I ended up getting it to work in the SQL statement that retrieves the database. I appreciate your help!
I agree. Here's the link:
subject: Alphabetizing an ArrayList
It's not a secret anymore!