Programming-Idioms

History of Idiom 28 > diff from v46 to v47

Edit summary for version 47 :
New Java implementation by user [Canem Inops ]

Version 46

2019-09-26, 16:02:03

Version 47

2019-09-26, 17:04:15

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Imports
import java.util.Comparator;
Code
items.stream().sorted(Comparator.comparing(x -> x.p))