{}
run-icon
Main.java
// Online Java Compiler // Use this editor to write, compile and run your Java code online import java.util.*; class HelloWorld { public static void main(String[] args) { List<Test> list = Arrays.asList(new Test(true, 5), new Test(false, 7), new Test(true, 1), new Test(false, 9)); list.sort(Comparator.comparing(Test::bool).thenComparing(Test::number)); System.out.println(list); System.out.println("Try programiz.pro"); } //public static record Test(boolean bool, int number) {} public static class Test { boolean bool; int number; public Test(boolean bool, int number) { this.bool = bool; this.number = number; } public boolean bool() { return bool; } public int number() { return number; } public String toString() { return "{" + bool + "," + number + "}"; } } }
Output