62,615
社区成员
发帖
与我相关
我的任务
分享
public class commonTest {
public static void main(String args[]) {
String[] tmpStrs = new String[] { "1", "3", "2", "5", "4" };
Arrays.sort(tmpStrs, new commonTest().new ComparatorTest());
for (String s : tmpStrs)
System.out.print(s + " ");
}
class ComparatorTest implements Comparator<Object> {
@Override
public int compare(Object o1, Object o2) {
int i = Integer.parseInt(String.valueOf(o1));
int j = Integer.parseInt(String.valueOf(o2));
if (i > j)
return -1;
if (i < j)
return 1;
return 0;
}
}
}