我想知道在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
}
非常感謝您的幫助。
不,你不能。 'if'不能被'switch'完全替換。 – khelwood