0 points

Sorting List of object


dashboard

Mon Jun 15 2020 12:33:08 GMT+0000 (UTC)

Posted by @pratik.gtm #dart

main() {
  List customers = [];
  customers.add(Customer('Jack', 23));
  customers.add(Customer('Adam', 27));
  customers.add(Customer('Katherin', 25));

  customers.sort((a, b) => a.age.compareTo(b.age));
  print('Sort by Age: ' + customers.toString());

  customers.sort((a, b) => a.name.compareTo(b.name));
  print('Sort by Name: ' + customers.toString());
}
content_copy Copy