Loading

String截取

1.str.substring(start,end)

end可以省略
eg
1.取字符串的前i个字符:str=str.Substring(0,i);
2.去掉字符串的前i个字符str=str.Substring(i)

2.replaceAll(resource,result)

支持正则
eg
String spec = "IP:".concat(sourceIp.replaceAll(":",":PORT").replaceAll(";:",";IP"));

3.String string2 = string.replace("old","new");

4.Object--json--String

List list = (List)result.getResData().get("list");
//list-->jsonArry
JSONArray jsonArray= JSONArray.parseArray(JSON.toJSONString(list));
//jsonArry-->String
String string = jsonArray.toJSONString();
String string2 = string.replace("childDeptList","childrenDeptList");
//String-->jsonArry
jsonArray= JSONArray.parseArray(string2);
//jsonArry-->list
List list2 = JSONObject.parseArray(jsonArray.toJSONString(), DeptDTO2.class);

posted @ 2022-01-24 17:39  风萧萧5  阅读(256)  评论(0)    收藏  举报