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

后端 未结 11 2129
夕颜
夕颜 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:23

    Here it is working solution:

    var sampleList = ['1', '2', '3', '3', '4', '4'];
    //print('orignal: $sampleList');
    sampleList = Set.of(sampleList).toList();
    //print('processed: $sampleList');
    

    Output:

    orignal: [1, 2, 3, 3, 4, 4]
    processed: [1, 2, 3, 4]
    

提交回复
热议问题