String转map

String map = "{user=0, name=acba334a0d, arg=2018, userCode=001}";
System.out.println(map);
if (map.startsWith("{")) {
    map = map.substring(1, map.length());
}
if (map.endsWith("}")) {
    map = map.substring(0, map.length() - 1);
}

Map map1 = new HashMap(16);
String[] out = map.split(",");
for (String anOut : out) {
    String[] inn = anOut.split("=");
    map1.put(inn[0], inn[1]);
}
System.out.println(map1);

你可能感兴趣的:(小技巧)