I have this code that sorts my arrayLists for different card suites (clubs, diamonds, hearts, and spades). Is there any way to write the following code so I do not have to write it for each ArrayList?
String clubsLabel = "Clubs";
String diamondsLabel = "Diamonds";
String heartsLabel = "Hearts";
String spadesLabel = "Spades";
Collections.sort(clubs, new cardIdSorter());
System.out.printf("%-12s", clubsLabel);
for(PlayingCard clubsCard: clubs) {
System.out.print(clubsCard);
}
System.out.println(" ");
Collections.sort(diamonds, new cardIdSorter());
System.out.printf("%-12s", diamondsLabel);
for(PlayingCard diamondsCard: diamonds) {
System.out.print(diamondsCard);
}
System.out.println(" ");
Collections.sort(hearts, new cardIdSorter());
System.out.printf("%-12s", heartsLabel);
for(PlayingCard heartsCard: hearts) {
System.out.print(heartsCard);
}
System.out.println(" ");
Collections.sort(spades, new cardIdSorter());
System.out.printf("%-12s", spadesLabel);
for(PlayingCard spadesCard: spades) {
System.out.print(spadesCard);
}