For loop to search for word in string

后端 未结 4 1243
孤城傲影
孤城傲影 2021-01-18 11:12

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 t

4条回答
  •  暖寄归人
    2021-01-18 11:19

    Try splitting the string on whitespace:

    String suit = cardArray.get(card);
    for (String word : suit.split("\\s+")){
        if (word.contains("SPADES")){
            suit = "SPADES";            
        }
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题