首页 > 编程语言 > 详细

Java7 switch新特性

时间:2014-03-27 06:18:15      阅读:436      评论:0      收藏:0      [点我收藏+]

在Java7之前,switch只能匹配整数值,和字符;而Java7添加了字符串的匹配特性。

代码如下:

bubuko.com,布布扣
 1 package blog;
 2 
 3 
 4 public class Main {
 5     public static void show(String str) {
 6         switch (str) {
 7             case "people":
 8                 System.out.println("Input string is people");
 9                 break;
10             case "school":
11                 System.out.println("Input string is school");
12                 break;
13             case "bird":
14                 System.out.println("Input string is bird");
15                 break;
16             default:
17                 System.out.println("Others");
18         }
19     }
20     
21     public static void main(String[] args) {
22         show("people");
23         show("bird");
24         show("dfkdf");
25     }
26 }
View Code

Java7 switch新特性,布布扣,bubuko.com

Java7 switch新特性

原文:http://www.cnblogs.com/wss-is-knight/p/3627094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!