提取字符串中两个双引号的内容并放入集合中
最近在写项目的时候遇到字符串提取分号中的内容 在这里说一下
@Test
public void testSetString() {
String str="[\"14\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\",\"26\",\"27\",\"28\"]";
System.out.println(str);
Pattern p1=Pattern.compile("\"(.*?)\"");
Matcher m = p1.matcher(str);
ArrayList<Integer> list = new ArrayList<Integer>();
while (m.find()) {
list.add(Integer.parseInt(m.group().trim().replace("\"","")));
}
System.out.println(list);
}
然后输出就是这个
["14","16","17","18","19","20","21","22","23","24","25","26","27","28"]
[14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]
希望能够帮助到你