我有一个像这样的字符串:[name ;24, name;23, name;22]
。我如何分割这个字符串以仅获取“;”之后的数字?
最佳答案
String s = "[name ;24, name;23, name;22]";
String couples[] = s.replace("]", "").split(",");
int ages[] = new int[couples.length];
for (int i=0; i< couples.length; i++)
ages[i] = Integer.parseInt(couples[i].split(";")[1]);
关于java - 分割后如何得到正确的子串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5890760/