I can't seem to find the syntax needed for the for loop in this method. I am looking to iterate through the words in the string suit
.
EDIT: one thing to note is that cardArray is a ArrayList.
public String getSuit(int card){
String suit = cardArray.get(card);
for (String word : suit){
if (word.contains("SPADES")){
suit = "SPADES";
}
}
return suit;
}
You could use
for (String word : suit.split(" ")) {
to split on every space character (U+0020).
Alternatively:
for (String word : suit.split("\\s+")) {
This splits on every sequence of whitespace character (this includes tabs, newlines etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With