java分割(split)输出通过","分割的字符
时间:2010-09-25 来源:日光倾城。
1 import java.util.Arrays;
2
3 public class TestSplit {
4 public static void main(String[] args) {
5 String str = new String("5,8,7,4,3,9,1,2,6");
6 String[] testString = str.split(",");
7 int[] test = new int[testString.length];
8 // String to int
9 for (int i = 0; i < testString.length; i++) {
10 test[i] = Integer.parseInt(testString[i]);
11 }
12 // 排序输出
13 System.out.println("正序输出");
14 Arrays.sort(test);
15 // asc sort
16 for (int j = 0; j < test.length; j++) {
17 System.out.println(test[j]);
18 }
19 System.out.println("倒序输出");
20 // desc
21 for (int i = (test.length - 1); i >= 0; i--) {
22 System.out.println(test[i]);
23 }
24 }
25 }
相关阅读 更多 +