Section 17.5.2 Filtering Strings Then Sorting Them in Case-Insensitive Ascending Order

Stream method sorted (p. 748) can receive a Comparator as an argument to specify how to compare stream elements for sorting.

• By default, method sorted uses the natural order for the stream’s element type.

• For Strings, the natural order is case sensitive, which means that "Z" is less than "a". Passing the predefined Comparator String.CASE_INSENSITIVE_ORDER performs a case-insensitive sort.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.