[Java] 纯文本查看 复制代码 public static void sort1(List<String> list) {
//集合排序工具传入一个比较器
for (int i = 0; i < list.size() - 1; i++) {
int indexMax = i;
for (int j = i + 1; j < list.size(); j++) {
String s1 = list.get(i);
String s2 = list.get(j);
char c1 = s1.toCharArray()[0];
char c2 = s2.toCharArray()[0];
if (c1 > c2) {
indexMax = j;
}
}
//交换位置
change(list, i , indexMax);
}
}
public static void change(List<String> list, int i, int indexMax) {
String temp = list.remove(indexMax);
list.add(indexMax - 1, list.get(i));
list.remove(i);
list.add(i, temp);
}
不用Collections类就这样吧! |