相关疑难解决方法(0)

如何删除飞镖列表中的重复项?list.distinct()?

如何从列表中删除重复项而不用一套搞砸?有像list.distinct()的东西吗?还是list.unique()?

void main() {
  print("Hello, World!");

  List<String> list = ['abc',"abc",'def'];
  list.forEach((f)=>print("this is list $f"));

  Set<String> set = new Set<String>.from(list);
  print("this is #0 ${list[0]}");
  set.forEach((f)=>print("set: $f"));

  List<String> l2= new List<String>.from(set);
  l2.forEach((f)=>print("This is new $f"));

}


Hello, World!
this is list abc
this is list abc
this is list def
this is #0 abc
set: abc
set: def
This is new abc
This is new def
Run Code Online (Sandbox Code Playgroud)

编辑:thx的答案. 设置似乎更快!!但它失去了项目的顺序:/

list dart

18
推荐指数
15
解决办法
1万
查看次数

标签 统计

dart ×1

list ×1