62,615
社区成员
发帖
与我相关
我的任务
分享
String[] temp = str.split(",");
String value="";
for(int i=0;i<n;i++){//n是你输入的
if(i!=0){
value+=",";
}
value+=temp[i];
}
...
public static void main(String[] args) throws Exception {
String str="1,232,21,12212,12";
int i = 3;
Matcher m = Pattern.compile("(,?\\d+){" + i + "}").matcher(str);
if(m.find()){
String s = m.group();
System.out.println(s);
}
}