Skip to content
Quiz · Lambdas and the Stream API · lesson 6 of 12

Quiz — reversed

What does the program print?

JAVA
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> ws = new ArrayList<>(
            List.of("pear", "banana", "fig", "apple"));
        ws.sort(Comparator.comparing(String::length).reversed());
        System.out.println(ws);
    }
}