The switch statement works with several types. You can switch on int, char, String, and enum values. Here's a String example:
String command = "start";
switch (command) {
case "start":
System.out.println("Starting...");
break;
case "stop":
System.out.println("Stopping...");
break;
case "restart":
System.out.println("Restarting...");
break;
default:
System.out.println("Unknown command");
}
String matching is case-sensitive. "Start" would not match "start", so you'd hit the default block.
You cannot switch on long, float, double, or boolean. If you need to branch on those types, use if-else instead.