I need to change the following if\'s to a switch-case while checking for a String, to improve the cyclomatic complexity.<
Everybody is using at least Java 7 now, right? Here is the answer to the original problem:
String myString = getFruitString();
switch (myString) {
case "apple":
method1();
break;
case "carrot":
method2();
break;
case "mango":
method3();
break;
case "orange":
method4();
break;
}
Notes
String.equals.if-else statements (as in cHao's answer).