Skip to main content
Java Code Completion Hard +35 XP

Lambda Comparator

Complete the lambda to sort by name length.

JavaFill in the blank
list.sort(Comparator.___(String::length));

Type the missing code

Show answer and explanation

Answer: comparingInt

Comparator.comparingInt extracts an int key function for comparison. String::length gives the sort key.

Hint: Which Comparator factory accepts an int extractor?

What this challenge tests

Code Completion in Java: lambdas, comparator, functional.

Related challenges