码迷,mamicode.com
首页 > 编程语言 > 详细

Java7中Switch语句支持String

时间:2015-06-05 14:04:15      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:实例   string   java   

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

Java7中Switch语句支持String

标签:实例   string   java   

原文地址:http://blog.csdn.net/topwqp/article/details/46375595

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!