Logo

Programming-Idioms

History of Idiom 28 > diff from v54 to v55

Edit summary for version 55 by programming-idioms.org:
Restored version 52

Version 54

2020-02-26, 06:45:54

Version 55

2020-02-29, 21:04:17

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.

Code
List<String> users =["a","b","c"];
users.sort((a, b) => a.length.compareTo(b.length));
Code
  List<String> users =["a","b","c"];
 users.sort((a, b) => a.length.compareTo(b.length));
Code
items.sort((a, b) => (a.p).compareTo(b.p));