map.toString 后在在map

  • Post author:
  • Post category:其他


public static Map<String, String> string2Map(String singInfo){

//将map.toString后的串反转成map

String str1 = singInfo.replaceAll(“\\{|\\}”, “”);//singInfo是一个map  toString后的字符串。

String str2 = str1.replaceAll(” “, “”);

String str3 = str2.replaceAll(“,”, “&”);

Map<String, String> map = null;

if ((null != str3) && (!””.equals(str3.trim())))

{

String[] resArray = str3.split(“&”);

if (0 != resArray.length)

{

map = new HashMap(resArray.length);

for (String arrayStr : resArray) {

if ((null != arrayStr) && (!””.equals(arrayStr.trim())))

{

int index = arrayStr.indexOf(“=”);

if (-1 != index) {

map.put(arrayStr.substring(0, index), arrayStr.substring(index + 1));

}

}

}

}

}

return map;

}