How to check if a string starts with one of several prefixes?

前端 未结 7 1108
广开言路
广开言路 2020-11-27 06:04

I have the following if statement:

String newStr4 = strr.split(\"2012\")[0];
if (newStr4.startsWith(\"Mon\")) {
    str4.add(newStr4);
}

I

相关标签:
7条回答
  • 2020-11-27 06:49

    Do you mean this:

    if (newStr4.startsWith("Mon") || newStr4.startsWith("Tues") || ...)
    

    Or you could use regular expression:

    if (newStr4.matches("(Mon|Tues|Wed|Thurs|Fri).*"))
    
    0 讨论(0)
提交回复
热议问题