67,513
社区成员
发帖
与我相关
我的任务
分享
String str="1,23,2,43,67,34";
Pattern p=Pattern.compile(",");
Matcher m=p.matcher(str);
int beginpos=0;
List<String> list=new ArrayList<String>();
while(m.find()){
list.add(str.substring(beginpos, m.end()-1));
beginpos=m.end();
}
Collections.sort(list,new Comparator<String>(){
public int compare(String o1, String o2) {
int a=Integer.parseInt(o1);
int b=Integer.parseInt(o2);
if(a>b)
return -1;
else if(a==b)
return 0;
else
return 1;
}
});
System.out.println(list);
}
}