Use string in switch case in java

前端 未结 13 1784
盖世英雄少女心
盖世英雄少女心 2020-12-01 07:30

I need to change the following if\'s to a switch-case while checking for a String, to improve the cyclomatic complexity.<

13条回答
  •  没有蜡笔的小新
    2020-12-01 07:48

    Java 8 supports string switchcase.

    String type = "apple";
    
    switch(type){
        case "apple":
           //statements
        break;
        default:
           //statements
        break; }
    

提交回复
热议问题