I'm trying to figure out how to sort the arrayLists that come out of a .txt file. I want to be able to sort them alphabetically by name. Here is an example of how the txt file is listed:
Alvarez, Eliezer
74
2B
IA
22
Bowman, Matt
67
P
A
26
Each piece is on a single line by itself (except lastName, firstName being on a line together).
Is there a way to do a collections sort that will adjust the rest of the Arraylists based off the name Arraylist? Thanks.
Scanner keyboard = new Scanner(System.in);
String filename;
fileName = "cardinals.txt";
File baseball = new File(fileName);
if (!baseball.exists()) {
System.out.println("The input file was not found.");
System.exit(0);
}
ArrayList<String> name = new ArrayList<>();
ArrayList<Integer> number = new ArrayList<>();
ArrayList<String> position = new ArrayList<>();
ArrayList<String> status = new ArrayList<>();
ArrayList<Double> age = new ArrayList<>();
Scanner stats = new Scanner(baseball);
if (!stats.hasNext()) {
System.out.println("The file is empty.");
}
else {
while (stats.hasNext()) {
name.add(stats.nextLine());
number.add(stats.nextInt());
position.add(stats.next());
status.add(stats.next());
age.add(stats.nextDouble());
try {
stats.nextLine();
} catch (Exception e) {
}
}
} stats.close();
sortArrayPosition();
sortArrayPosition (ArrayList<String> name, ArrayList<Integer> number, ArrayList<String> position, ArrayList<String> status, ArrayList<Double> age) {