public class NewMain {
public static void main(String[] args) {
ArrayList<String> array = new ArrayList<>();
array.add("Ace of Hearts");
array.add("King of Clubs");
array.add("Three of Spade");
array.add("Ace of Hearts");
array.add("Ten of Clubs");
for(String s: array)
System.out.println(s+"at postion: "+array.indexOf(s));
}
}
IndexOf() returns the first occurence of the object in an ArrayList. Assuming my code is the hand of a poker player, and I want to know the indices of the cards he is holding. Ace of Hearts is at positon 1 and 4. But IndexOf() returns as position 1 and 1 for both occurences of Ace of Hearts.
Question:
1)Is there any other way of getting the value?
2)Should I use someother Data Structure like HashMap or something else?