日期:2014-05-20 浏览次数:20767 次
String[] s = { "5", "3", "1", "4" };
Arrays.sort(s);
public static void main(String[] args) {
String s1="5,3,1,4";
String[] s2 = s1.split(",");
Arrays.sort(s2);
String s3 = Arrays.deepToString(s2).replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(" ", "");
System.out.println(s3);
StringBuilder sb = new StringBuilder(s3);
sb.reverse();
System.out.println(sb.toString());
}
String s5 = "5,3,1,4";
String[] sArray = s5.split(",");
int[] iArray = new int[sArray.length];
for (int i = 0; i < sArray.length; i++) {
iArray[i] = Integer.parseInt(sArray[i]);
}
Arrays.sort(iArray);
for (int i = 0; i < iArray.length; i++) {
System.out.print(iArray[i] + " ");
}
System.out.println();
for (int i = iArray.length - 1; i > -1; i--) {
System.out.print(iArray[i] + " ");
}
System.out.println();
package main.action;
import java.util.Arrays;
public class test {
public static void main(String[] args) throws Exception {
String number = "3,1,4,5,2";
numSort(number, "asc");
}
public static void numSort(String numbers, String sort) {
String[] num = numbers.split(",");
StringBuffer nums = new StringBuffer();
Arrays.sort(num);
if (sort.equals("asc")) {
for (int i = 0; i < num.length; i++) {
nums.append(num[i]).append(",");
}
System.out.println(nums.toString().substring(0,nums.length()-1));
}else if(sort.equals("desc")){
for( int i=num.length-1;i>=0;i--){
nums.append(num[i]).append(",");
}
System.out.println(nums.toString().substring(0,nums.length()-1));
}
}
}
import java.util.Arrays;
public class Test001 {
public static void main(String[] args) throws IllegalAccessException {
String s5 = "5,3,1,4";
System.out.println(sort(s5, ","));
System.out.println(sortDesc(s5, ","));
}
static String sort(String sourceStr, String splitStr) {