我有json数组的对象,它们将具有" offer_name"每个对象中的字段。我想通过自定义" offer_name"来命令/排序我的json对象。订购。请让我知道如何实现这一目标?
我需要按以下顺序订购优惠
enum OffersOrder { BEST("BEST"),GOLD("GOLD"),RISK("RISK"),STANDARD("STANDARD"),PUBLIC("PUBLIC");
String sound;
OffersOrder(String s) { sound = s; }
}
答案 0 :(得分:0)
这是你如何做到的:
List<OffersOrder> l = new ArrayList<>();
// code to populate your list
...
// sorting
java.util.Collections.sort(l, new Comparator<OffersOrder>(){
@Override
public int compare(OffersOrder o1, OffersOrder o2) {
// this method should return a negative value if o1 < o2
// this method should return 0 if o1 == o2
// this method should return a positive value if o1 > o2
return 0;
}
});