How to delete duplicates in a dart List? list.distinct()?

后端 未结 11 2125
夕颜
夕颜 2020-12-01 05:21

How do i delete duplicates from a list without fooling around with a set? Is there something like list.distinct()? or list.unique()?

void main() {
  print(\"         


        
11条回答
  •  佛祖请我去吃肉
    2020-12-01 05:30

    this is other way...

    final reducedList = [];
    
    list.reduce((value, element) {
        if (value != element) reducedList.add(value);
        return element;
    });
    
    reducedList.add(list.last);
    
    print(reducedList);
    

提交回复
热议问题