Java的List操作

 

    public static void testJava(){
    	
        Map m1 = new HashMap(); 
        m1.put("Zara", "8");
        m1.put("Mahnaz", "31");
        m1.put("Ayan", "12");
        m1.put("Daisy", "14");
        System.out.println();
        System.out.println(" Map Elements");
        System.out.print("\t" + m1);
        
        if (m1.containsKey("Mahnaz")) {
        	System.out.println(m1.get("Mahnaz"));
        }
        
        if (m1.get("Mahnaz").equals("31")) {
            System.out.println("xxxxx");
        }

        /*  -------------------------  */
    	
        List<String> cellList1=new ArrayList<>();
        cellList1.add("aa");
        cellList1.add("bb");
        
        Map<String,Object> module1=new HashMap<>();
        module1.put("code","04XMEXAXD10MG19800000010");
        module1.put("cellList",cellList1);
        
        List<Map<String,Object>> moduleList1=new ArrayList<>();
        moduleList1.add(module1);
        System.out.println("moduleList1=" + moduleList1);
        
        /*  -----------  来自send()函数 --------------  */
		
		Map<String, Object> requestMap2 = new HashMap<String, Object>();
        String requestMsg = new JsonSerializer().deep(true).serialize(moduleList1);
		
		
        System.out.println("requestMsg=" + requestMsg);
        
        String data = "[{a:b}]";
        String flag = "";
        
        /*  ------------ 来自test 或 send()函数  -------------  */
        Map<String, Object> requestMap = new HashMap<String, Object>();
        requestMap.put("p1", data);
        requestMap.put("p2", System.currentTimeMillis());
        requestMap.put("p3", flag);
        System.out.println("requestMap=" + requestMap);
        
        /*  -----------  来自 getRequest()函数 --------------  */
        
	    try {
	        String string2 = (new JsonSerializer()).serialize(requestMap);
	
	        System.out.println("string2=" + string2);
	        
			/*  -----------  来自test 或 parsToMap()函数 --------------  */
			
	        ObjectMapper mapper = new ObjectMapper();
	        Map map = mapper.readValue(string2, Map.class);
	        String result=map.get("p2").toString();

	        System.out.println("result=" + result);
	        
	        if(isNotEmpty(map.get("p3"))){
		        System.out.println("returnstring=" + map.get("p3").toString());
	        }else {
		        System.out.println("returnstring=" + map.get("p3").toString());
	        }
			
			
        /*  -----------  来自receivedata()函数 --------------  */
		
			String packList = "{'code': 5}";
			JSONObject jsonObject = JSONObject.parseObject(packList);
			//Map<String, String> params = JSONObject.parseObject(jsonObject.toString(), new TypeReference<Map<String, String>>(){});
			Map<String, Object> params = JSONObject.parseObject(jsonObject.toString(), new TypeReference<Map<String, Object>>(){});
			System.out.println(params.get("code"));
	        
	        
	    }catch (Exception e){
	        e.printStackTrace();
	    }
        
    }

它的运行结果会是

 Map Elements
	{Daisy=14, Ayan=12, Zara=8, Mahnaz=31}31
xxxxx
moduleList1=[{code=04XMEXAXD10MG19800000010, cellList=[aa, bb]}]
requestMsg=[{"code":"04XMEXAXD10MG19800000010","cellList":["aa","bb"]}]
requestMap={p1=[{a:b}], p2=1617690850558, p3=}
string2={"p1":"[{a:b}]","p2":1617690850558,"p3":""}
result=1617690850558
returnstring=
5

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值