Skip to content
Advertisement

Tag: sorting

Sort A List of an Object with other object’s method

In the bellow code, with such classes, how can I sort an ArrayList of Students by the score the got from Courses List? I mean how can I sort a List of a specific class by an attribute of this class which is a child of another class. Answer Your “Student” class is confusing. Based on the name, it sounds

Sort arrays using lambda

I want revers-sort java8. I don’t want use stream. Here is an example: I want it like this: {5, 4, 3, 2, 1}; So my code is this But I get an error message: Operator ‘-‘ cannot be applied to ‘T’, ‘T’ How can I reverse sort and sort? Is there a better way? Answer You can try if you

Java: Order a list of Objects based on Calendar date?

I have a list of Java Objects that all contain the following field: I want to order the list of objects based on the above field , the object with date field most recent first. What is the best way to do so? Answer You can use Comparator.comparing, suppose you have List<Entity> then you can do this way

Advertisement