How to parse the string into map

后端 未结 5 1171
失恋的感觉
失恋的感觉 2021-02-15 02:24

have a string like A=B&C=D&E=F, how to parse it into map?

5条回答
  •  猫巷女王i
    2021-02-15 03:27

    String  t = A=B&C=D&E=F;
    Map map = new HashMap();
    String[] pairs = t.split("&");
    //TODO 1) Learn generis 2) Use gnerics    
    for (String pair : pairs)
    {
        String[] kv = pair.split("=");
        map.put(kv[0], kv[1]);
    }
    

提交回复
热议问题