1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| List myList = ["香蕉", "苹果"];
for (var item in myList) { print(item); // 香蕉 苹果 }
myList.forEach((element) { print(element); // 香蕉 苹果 });
// map 修改集合中的数据 List l1 = [1, 3, 5]; var newList = l1.map((value) { return value * 2; }); print(newList.toList());
// where 循环遍历数组满足条件返回新数组 List l2 = [1, 2, 3, 4, 5]; var new2 = l2.where((element) { return element > 4; }); print(new2.toList());
// any 只要集合里面有满足条件的就返回true List l3 = [1, 2, 3, 4, 5]; var new3 = l2.any((element) { return element > 4; }); print(new3); // true
// every 集合里面每一个都满足条件返回true List l4 = [1, 2, 3, 4, 5]; var new4 = l4.every((element) { return element > 4; }); print(new4); // false
|