gpt4 book ai didi

java - 如何反转数组?

转载 作者:行者123 更新时间:2023-12-01 23:45:02 24 4
gpt4 key购买 nike

XXXXXVO[] general = XXXX.getXXXX();

Comparator comparator = new Comparator() {
DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
public int compare(Object obj1, Object obj2) {

XXXXX gen11 = (XXXXXVO) obj1;
XXXXX gen22 = (XXXXXVO) obj2;

String firstString = gen11.getXXXXX().toString();
String secondString = gen22.getXXXX().toString();

if (secondString == null || firstString == null) {
return 0;
}


return f.parse(firstString).compareTo(f.parse(secondString));

}
};

Arrays.sort(general, comparator);

上面是按升序对数组进行排序的代码。我希望按降序排列。我怎样才能在 JDK 1.4 中逆转这个问题?

最佳答案

只需颠倒比较的顺序即可:

return f.parse(secondString).compareTo(f.parse(firstString))

关于java - 如何反转数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17208832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com