List、Set
List:有序、可重复
Set:无序、不重复
互相转化
List list = [1, 2, 1];
Set set = list.toSet();
List sList = set.toList();
遍历forEach
List list = [1, 2, 1];
list.forEach((e) {
print(e);
});
映射map
List list = [1, 2, 1];
List m = list.map((e) => ++e).toList();
过滤where
List list = [1, 2, 1];
List m = list.where((e) => e > 1).toList();
任一满足any
List list = [1, 2, 1];
bool b = list.any((e) => e == 2);
全部满足every
List list = [1, 2, 1];
bool b = list.every((e) => e > 0);
Map
获取所有键keys
获取所有值values
映射map
遍历forEach
Map person = {
"name": "Lily",
"age": 12,
};
person.forEach((key, value) {
print("$key: $value");
});
标签:toList,Set,map,基础,list,Dart,语法,forEach,List From: https://www.cnblogs.com/-ori/p/17160666.html