public class test { public static void main(String[] args) { String s = "58627"; //split转换s为arr数组 String[] arr = s.split(""); //冒泡对arr数组进行排序 for(int i=0;i<arr.length-1;i++){ for (int j=0;j<arr.length-1-i;j++) { if(Integer.parseInt(arr[j])>Integer.parseInt(arr[j+1])){ String temp = arr[j+1]; arr[j + 1] = arr[j]; arr[j] = temp; } } } //数组arr转换成字符串finalString StringBuilder sb = new StringBuilder(); for (String s1 : arr) { sb.append(s1); } String finalString = sb.toString(); System.out.println(finalString); } }