Switch
jdk1.7的switch语句增加了对字符串类型的支持。其实现的原理是通过字符串的hash值来比较的,代码示例如下:
1 String name = "KiDe"; 2 // Welcome the owner! 3 switch (name) { 4 case "KiDe": 5 System.out.println("Welcome the owner!"); 6 break; 7 default: 8 System.out.println("Welcome the other!"); 9 }