Code:
ArrayList<String> lastname2 = new ArrayList();
//int x = lastname.size() - 1;
int x = lastname.size();
//System.out.print(x);
do
{
lastname2.add(lastname.get(x));
x = x-1;
}while (x != -1);
Collections.sort(lastname, String.CASE_INSENSITIVE_ORDER);
String moreinput = JOptionPane.showInputDialog(null, counter + " people voted.\n\rTheir last names:\n\r " + lastname + "\n\rEnter the last name of whoever you want to look up: ");
int finalindex = lastname2.indexOf(moreinput);
JOptionPane.showMessageDialog(null, "Their information:\n\r" + firstname.get(finalindex) + lastname2.get(finalindex) + "\n\r" + address.get(finalindex) + "\n\r" + city.get(finalindex) + ", " + state.get(finalindex) + "\n\r" + zipcode.get(finalindex));
This part of a voting poll program I'm making is supposed to duplicate the arraylist "lastname" and call the new arraylist "lastname2," then sort lastname arraylist alphabetically, while letting you look up the information of any voter by referencing lastname2. The two lines commented out are some variations I've been experimenting with (the println(x) is just to see if x even gets a value set (spoiler: it doesnt....))
I'm very new to java, so any help solving this would be appreciated.
--
I have a feeling the solution is very simple and I'm just missing something, or if somebody has a suggestion as to a better way to code this instead of a DoWhile loop....