Skip to content

Sorting

Read · 1 of 3

Sorting with a rule

Arrays.sort(a) sorts an array smallest first. For a list: Collections.sort(list).

To sort your own way, pass a rule that compares two items: (a, b) -> a.length() - b.length() puts shorter strings first. A negative answer means a goes first.