There exists some questions regarding sorting by string variables of custom objects. I did follow them and used comparators. However, in my custom object there are multiple string and Integer values and I want to sort objects with different attribute unpon whatever was requested. I followed this to just sort one by one attribute.
For example
public class CustomerObj(){
Integer id;
String name;
String city;
Integer zipCode;
}
I will only need to sort by ONE of the attributes each time the user requests. On top of this user will also request whether they want the list to be sorted in ascending or desending order. So for example if I were to get a request from use to sort it by Id and in desceding order I am unable to pass in a comparator and Collections.reverseOrder();
Summary: I want to sort by different attributes (not multiple at the same time) with whatever attribute requested and with whichever order requested. Example User request sort by id in descending order. response:
[
obj{id: 3},
obj{id: 2},
obj{id: 1}
]