import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class T {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add("92.8");
list.add("68.9");
list.add("168.61");
list.add("242");
list.add("317");
list.add("105");
// 字符串排序
Collections.sort(list);
System.out.println(list.toString()); // [105, 168.61, 242, 317, 68.9, 92.8]
Collections.sort(list, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return new Double((String) o1).compareTo(new Double((String) o2));
}
});
System.out.println(list.toString()); // [68.9, 92.8, 105, 168.61, 242, 317]
}
}
排序
最新推荐文章于 2024-03-28 00:29:10 发布