我想知道您是否可以在 switch case 的情况下使用诸如 'contains()' 之类的方法。我正在尝试将以下 if 语句转换为 switch case:
String sentence;
if(sentence.contains("abcd")){
// do command a
}
else if(sentence.contains("efgh")){
// do command b
}
else if(sentence.contains("ijkl")){
// do command c
}
else{
//do command d
}
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助。