小编Fli*_*sie的帖子

在 switch case 语句中使用方法

我想知道您是否可以在 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)

非常感谢您的帮助。

java methods if-statement switch-statement

5
推荐指数
1
解决办法
5693
查看次数

标签 统计

if-statement ×1

java ×1

methods ×1

switch-statement ×1