-2

I have json array of objects which will have "offer_name" field in every object. I would like to order/sort my json objects by custom defined "offer_name" order. Please let me know how can I achieve this?

I need to order offers in below order

enum OffersOrder { BEST("BEST"),GOLD("GOLD"),RISK("RISK"),STANDARD("STANDARD"),PUBLIC("PUBLIC");
String sound;    
OffersOrder(String s) { sound = s; }
}
1
  • 2
    What have you done so far? we will not write your code for you. show us what you have tried and we will try to help Commented Aug 7, 2017 at 6:47

1 Answer 1

0

This is how you can do that:

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;
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.