I have a list of elements of different types of players based on sports. I need to sort the list of players in the arrayList list by name to get started. If 2 players have the same name, you must sort these 2 players by name. Example: Format First Name Last Name Williams Robert Phillips Warren Dow John Phillips Mark
The way out should be Dow John Phillips Mark Phillips Warren Williams Robert
Now I only have sorting by first or last, I have the last atm in my code.
public static void sortPlayers(ArrayList playerList) { for (int i = 0; i < playerList.size(); i++) { for (int j = 0; j < playerList.size(); j++) { Collections.sort(playerList, new Comparator() { public int compare(Object o1, Object o2) { PlayerStats p1 = (PlayerStats) o1; PlayerStats p2 = (PlayerStats) o2; return p1.getPlayerLastName().compareToIgnoreCase(p2.getPlayerLastName()); } }); } } }
source share