Sorting an arraylist in Java language
Posted
by Computeristic
on Stack Overflow
See other posts from Stack Overflow
or by Computeristic
Published on 2010-03-13T17:38:23Z
Indexed on
2010/03/13
17:45 UTC
Read the original article
Hit count: 308
Hi,
I have an arraylist set up. I have input instuctions set up too, so that the user can enter one string, then one integer, then one string (the first name, the age, and the last name).
I need to sort the arraylist by the last name. The code I have entered so far is all under the main method:-
public static void main(String[] args) {
Name Name[] = new Name[50];
int count = 0;
for (int i=0; i<50; i++)
NewName[i] = new Name();
//ADD NEW TO ARRAYLIST NAME
String FName = JOptionPane.showInputDialog("first name");
int age = Integer.parseInt(JOptionPane.showInputDialog("age"));
String LName = JOptionPane.showInputDialog("last name");
NewName[count] = new Name(FName, age, LName);
count = count++;
}
//ITEMS SORT BY LAST NAME
//CODE FOR SORT GOES HERE
© Stack Overflow or respective owner