0

I need to sort common age names as sublist to the same age list item here below is the list which contains age and name , here i want to make sublist names to the same age item , need help

        class Details {
  final String name;
  final int age;

  Details(this.name, this.age);

  List <Details> list = [
    { Jack, 21},
    { Adam, 22},
    { Katherin, 24},
    { john, 22},
    { mike, 21}
  ]
}


Expected :
    
       List <Details> list = [
    { 21: ["jack", "mike",]},
    { 22: ["Adam", "john"]},
    { 24: ["Katherin"]}, ]
gopinath
  • 89
  • 1
  • 9

1 Answers1

0

Here you can find the way to make a sublist of common elements from list item

detailsTypeList = groupBy(list, (Details details) => details.age).entries.toList();
lemon
  • 14,875
  • 6
  • 18
  • 38
gopinath
  • 89
  • 1
  • 9