← Unit 4 · all exercises
Saved in this browser only

The longest word

Return the longest word in the list. If several tie, return the first of them. The list always has at least one word.

String longest(java.util.ArrayList<String> words)

Solution.java
Loading editor…
Results

Examples

  • Solution.longest(new java.util.ArrayList<>(java.util.List.of("a", "abc", "ab"))) → abc
  • Solution.longest(new java.util.ArrayList<>(java.util.List.of("only"))) → only

There are also 2 hidden tests you can't see. Solve the problem, not the examples.