Java7中Switch语句支持String
Java7新特性Swith语句中支持String
实例:
public class StringSwitch {
public static void main(String[] args) {
System.out.println(getExpendedMessage("one"));
System.out.println(getExpendedMessage("three"));
System.out.println(getExpendedMessage("five"));
}
static String getExpendedMessage(final String token)
{
switch (token)
{
case ("one"):
return "Token one identified";
case ("two"):
return "Token two identified";
case ("three"):
return "Token three identified";
case ("four"):
return "Token four identified";
default:
return "No token was identified";
}
}
}
输出如下:
Token one identified
Token three identified
No token was identified
参考:click here
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。