Suppose you have Client
class defined as
class Client {
private long dayInNumber;
private String clientName;
private String day;
//setters and getters ommitted for brevity and clarity
}
Then you have a list of clients
List<Client> clients = new ArrayList<>();
To sort that dayInNumber
you can either sort that in SQL (order by
clause) assuming the data is coming from SQLite.
Or you can create a custom Comparator<T>
of Client
objects to do the sorting in code as below
import java.util.Comparator;
public class ClientDayInNumberComparator implements Comparator<Client> {
@Override
public int compare(Client c1, Client c2) {
if(c1.getDayInNumber() > c2.getDayInNumber()) return 1;
else if(c1.getDayInNumber() < c2.getDayInNumber()) return -1;
else
return 0;
}
}
This will sort clients by dayInNumber in ascending order (1, 2, 3,...N). Then use it as follows
List<Client> clients = new ArrayList<>();
Collections.sort(clients, new ClientDayInNumberComparator());
Collections
is packed in java.utils
package which you'll need to import