日期:2014-05-20 浏览次数:20693 次
import java.util.Comparator;
import java.util.*;
public class SsvlistInfoCompare implements Comparator<String[]> {
/**
*
*/
public int compare(String[] a, String[] b) {
//如果a 大于b 返回 整数 1 、相等返回 0 、小于返回 -1
//按升序排列 如果要设置成降序写成b.compareTo(a);
int flag = a[0].compareTo(b[0]);
return flag;
}
public static void main(String[] strs) {
List<String[]> list = new ArrayList<String[]>();
for(int i = 0 ; i < 20 ; i++){
String[] ary = new String[1];
ary[0] = String.valueOf(i);
list.add(ary);
}
SsvlistInfoCompare s = new SsvlistInfoCompare();
//实现顺序或者倒序排列
Collections.sort(list, s);
for (int i = 0; i < list.size(); i++) {
String[] ary = list.get(i);
System.out.println(ary[0]);
}
}
}
import java.util.Comparator;
import java.util.*;
public class SsvlistInfoCompare implements Comparator<String[]> {
/**
*
*/
public int compare(String[] a, String[] b) {
//如果a 大于b 返回 整数 1 、相等返回 0 、小于返回 -1
//按升序排列 如果要设置成降序写成b.compareTo(a);
int flag = Integer.parseInt(a[0]) - Integer.parseInt(b[0]);
return flag;
}
public static void main(String[] strs) {
List<String[]> list = new ArrayList<String[]>();
for(int i = 0 ; i < 20 ; i++){
String[] ary = new String[1];
ary[0] = String.valueOf(i);
list.add(ary);
}
SsvlistInfoCompare s = new SsvlistInfoCompare();
//实现顺序或者倒序排列
Collections.sort(list, s);
for (int i = 0; i < list.size(); i++) {
String[] ary = list.get(i);
System.out.println(ary[0]);
}
}
}