本文共 1959 字,大约阅读时间需要 6 分钟。
1.示例代码
package main.test;import java.util.*;/** * Created by wwm on 2016/8/11. */public class TestSwitch { public static void main(String[] args) { List > orderList = initList(); for(Map map:orderList){ Set keySet = map.keySet(); for(String key:keySet){ switch (key){ case "orderNo": String orderNo = map.get("orderNo"); System.out.println(orderNo); break; case "sku": String sku = map.get("sku"); System.out.println(sku); break; case "price": String price = map.get("price"); System.out.println(price); break; case "name": String name = map.get("name"); System.out.println(name); break; case "mobile": String mobile = map.get("mobile"); System.out.println(mobile); break; default: System.out.println("you are too niu x"); break; } } } } private static List > initList(){ List > orderList = new ArrayList >(); Map map1 = new HashMap (); map1.put("orderNo","8888888"); map1.put("sku","898989"); map1.put("price","989898"); map1.put("name","Test"); map1.put("mobile","15886775760"); Map map2 = new HashMap (); map2.put("orderNo","8888888"); map2.put("sku","898989"); map2.put("price","989898"); map2.put("name","Test"); map2.put("mobile","15886775760"); orderList.add(map1); orderList.add(map2); return orderList; }}
2.运行结果
可以在项目中尝试着使用
转载于:https://my.oschina.net/nixi0608/blog/731185