JSONObject[] jsons=new JSONObject[10];
//排序
Arrays.sort(jsons, new Comparator<JSONObject>() {
public int compare(JSONObject o1, JSONObject o2) {
int aFirstWeight=0;
int aSecondWeight=0;
try{
aFirstWeight = Integer.parseInt(o1.get("order").toString());
}catch(Exception e){
aFirstWeight=0;
}
try{
aSecondWeight =Integer.parseInt(o2.get("order").toString());
}catch(Exception e){
aSecondWeight=0;
}
int diff = aFirstWeight - aSecondWeight;
if (diff > 0){
return 1;
}else if (diff < 0){
return -1;
}
return 0;
}
});
JAVA 数组排序
最新推荐文章于 2024-10-09 11:13:12 发布