Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:00
Show Gist options
  • Save adojos/8763573ae3612f705d326a5f0e6f96a5 to your computer and use it in GitHub Desktop.
Save adojos/8763573ae3612f705d326a5f0e6f96a5 to your computer and use it in GitHub Desktop.
Java: How-To Sort a List of Objects #java
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