How to sort Array List using Custom Order On many occasions we need to sort an array list or linked list based on custom logic. Suppose you have a Quiz application and you want to return questions based on a custom question id. e.g Request : ids = [ 88, 21, 43, 15, 64, 35 ] When you will fetch the Questions from Database you will be using a query something like below select * from question where id in (?) This will give you questions ordered by id by default. So to covert it in same order as requested order you can use view plain copy to clipboard print ? // ids = [ 88, 21, 43, 15, 64, 35 ] // questions = new ArrayList<Question>(); Collections.sort(questions, new Comparator<Question>() { @Override public int compare(QuestionDto q1, QuestionDto q...