解决java switch……case不能匹配字符串的方法
来源:互联网 发布:推荐算法 数据集 编辑:程序博客网 时间:2024/04/28 05:58
enum Animal { dog,cat,bear; public static Animal getAnimal(String animal){ return valueOf(animal ); } } public class Client { public void caseAnimal(String animal){ switch(Animal.getAnimal(animal)){ case cat: System.out.println("this is a cat"); break; case dog: System.out.println("this is a dog"); break; case bear: System.out.println("this is a bear"); break; } } public static void main(String[] args) { Client client = new Client(); client.caseAnimal("cat"); } }
public void switchCaseStr() { Map<String,Integer> map=new HashMap<String, Integer>(); map.put("hello", 1); map.put("haha", 2); map.put("yes", 3); map.put("in", 4); String str="hello"; switch(map.get(str)) { case 3: System.out.println("yes"); break; case 1: System.out.println("hello"); break; case 2: System.out.println("haha"); break; case 4: System.out.println("in"); break; default: System.out.println("default"); } }
- 解决switch……case不能匹配字符串的方法
- 解决switch……case不能匹配字符串的方法
- 解决java switch……case不能匹配字符串的方法
- 解决java switch……case不能匹配字符串的方法
- switch……case不能匹配字符串的方法
- switch……case不能匹配字符串的方法
- java switch case 用于字符串的方法
- 解决JAVA switch case 里面case A, A不能为 变量的问题
- String类不能switch…case的解决方案
- java中switch语句的case中不能抛出异常?
- 解决switch 多case问题的方法之一
- Java的switch-case语句
- java 解决switch case不支持String
- switch… case 语句的用法
- switch… case 语句的用法
- switch… case 语句的用法
- switch… case 语句的用法
- switch… case 语句的用法
- 对于求字符串中出现频率最高字符的算法实现
- Spring MVC 3 深入总结
- java.net.ConnectException: Connection timed out: connect 错误
- 千里马常有,而伯乐不常有
- GRE 简述(为cisco路由器配置GRE隧道举例)
- 解决java switch……case不能匹配字符串的方法
- spring mvc注解实现
- 裸考—歪理邪说通过系统分析师考试之一(分析2010上半年系统分析师上午试题1-5题)
- 贪心算法
- 分母不能为零
- OFBiz 的MVC框架
- try btrace before I proceed to work on dacapo.
- {!!}Windows 2003 上配置 VPN + NAT以及VPN的端口映射详解
- BTrace使用简介