如何从列表中删除重复项而不用一套搞砸?有像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的答案. 设置似乎更快!!但它失去了项目的顺序:/