I'm creating a poker game in Java, as of right now I am trying to find duplicate ranks in an ArrayList and printing them. My ArrayList (cards) contains ["3c", "3s", "Ad", "6h", "7h", "7s"]. When I use the method I've created
String firstChar;
public void twoPair() {
for(String t : cards) {
char rank_index = t.charAt(0);
firstChar = String.valueOf(rank_index);
}
for (String i : cards) {
if (i.startsWith(firstChar)) System.out.println(i);
}
}
I get an output of:
7h
7s
and similarily, If I add another 7 card (like 7c), I get all three of the 7 cards,
7h
7s
7c
but not the duplicates of rank 3 cards ("3c" and "3s"). Full code at https://github.com/aepries/A8-Poker