import java.util.Arrays;
public class TestSplit {
public static void main(String[] args) {
String str = new String("5,8,7,4,3,9,1,2,6");
String[] testString = str.split(",");
int[] test = new int[testString.length];
// String to int
for (int i = 0; i < testString.length; i++) {
test[i] = Integer.parseInt(testString[i]);
}
// 排序输出
System.out.println("正序输出");
Arrays.sort(test);
// asc sort
for (int j = 0; j < test.length; j++) {
System.out.println(test[j]);
}
System.out.println("倒序输出");
// desc
for (int i = (test.length - 1); i >= 0; i--) {
System.out.println(test[i]);
}
}
}
java分割(split)输出通过","分割的字符
最新推荐文章于 2021-04-13 16:10:59 发布