Java(版本7之前的版本)在switch / case中不支持String。但是您可以通过使用枚举来达到预期的结果。
private enum Fruit { apple, carrot, mango, orange;}String value; // assume inputFruit fruit = Fruit.valueOf(value); // surround with try/catchswitch(fruit) { case apple: method1; break; case carrot: method2; break; // etc...}


