Last active
March 9, 2023 11:00
-
-
Save adojos/8763573ae3612f705d326a5f0e6f96a5 to your computer and use it in GitHub Desktop.
Java: How-To Sort a List of Objects #java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Student> input = new ArrayList<Student>(); | |
input.add(new Student("Bill",76)); | |
input.add(new Student("Jane",94)); | |
input.add(new Student("George",68)); | |
input.sort((s1,s2) -> s1.getMarks() - s2.getMarks()); | |
System.out.print("Sorted List:"); | |
input.forEach(s -> System.out.print(s.getName()+" ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment