import java.util.Arrays;
public class StringDateSort {
public static void main(String[] args) {
String numString="23 10 -8 0 3 7 108";
String sortStr=sortNumberString(numString);
System.out.println("排序的结果是"+sortStr);
}
private static String sortNumberString(String numString) {
//1.将给定的字符串分解成多个数字格式字符串
String[] numStrings=toStringArray(numString);
//2.将字符串数组转成int数组
int[] nums=toIntArray(numStrings);
//3.对数组排序
sort(nums);
//4.将int数组转成字符串
return toString(nums);
}
private static String toString(int[] nums) {
StringBuffer stringBuffer=new StringBuffer();
for (int i = 0; i < nums.length; i++) {
if (i!=nums.length-1) {
stringBuffer.append(nums[i]+"<");
}else{
stringBuffer.append(nums[i]);
}
}
return stringBuffer.toString();
}
private static void sort(int[] nums) {
Arrays.sort(nums);
}
private static int[] toIntArray(String[] numStrings) {
int[] nums=new int[numStrings.length];
for (int i = 0; i < numStrings.length; i++) {
String s=numStrings[i];
nums[i]=Integer.parseInt(s);
}
return nums;
}
private static String[] toStringArray(String numString) {
String[] numberStr=numString.split(" ");
for (int i = 0; i < numberStr.length; i++) {
System.out.println("抽出数字"+numberStr[i]);
}
return numberStr;
}
}
字符串数组能进行排序???我只学过对int,float,double进行排序
一个升序的算法
public static void sort(String[] str){
for(int i=0;i
int index = i;
for(int j=i+1;j
maxStr = str[j];
index = j;
}
}
str[index] = str[i];
str[i] = maxStr;
}
}
说明白一点
怎么排序,给个你要实现的排序规则啊。