public class Forum1 {
public static void main(String[] args) {
String str="91 27 46 38 50";
System.out.println(sort(str));
}
public static String sort(String str){
String[]arr=str.split("\\s+");
Arrays.sort(arr);
StringBuilder sb=new StringBuilder();
for (String string : arr) {
sb.append(string+" ");
}
return sb.toString();
}
}
先把字符串spilt成字符串数组,然后数组排序 |