public class TestNNN {
public static void main(String[] args) {
String[] arr = new String[8];
for (int i = 0; i < arr.length; i++) {
arr[i] = RandomStringUtils.randomAlphanumeric(5);
System.out.println("排序前:" + arr[i]);
}
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j].toLowerCase().charAt(0) > arr[j + 1].toLowerCase().charAt(0)) {
String temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("------------排序后--------------");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
打开App,阅读手记