一、forEach
循环遍历集合数据
var list = ["香蕉", "苹果", "葡萄", "西瓜"];
list.forEach((value) {
print(value);
});
二、for in
循环遍历集合数据
var list = ["香蕉", "苹果", "葡萄", "西瓜"];
for (var item in list) {
print(item);
}
三、map
主要用于修改集合里的数据
var myList = [1, 3, 4,5,7,8,9];
var newList = myList.map((value) {
return value * 2;
});
print(newList.toList());
四、where
把满足条件的返回一个新的集合
var myList = [1, 3, 4,5,7,8,9];
var newList=myList.where((value){
return value>5;
});
print(newList.toList());
五、any
判断集合中有没有满足条件的数据,返回true或false
var myList = [1, 3, 4,5,7,8,9];
var newList=myList.any((value){
return value>5;
});
print(newList);
六、every
判断集合中是否都满足条件的数据,返回true或false
var myList = [1, 3, 4,5,7,8,9];
var newList=myList.every((value){
return value>5;
});
print(newList);