Using addAll() method to add all the elements of other lists to the existing list
main() {
// Creating lists
List gfg1 = ['Welcome','to'];
List gfg2 = ['GeeksForGeeks'];
// Combining lists
gfg1.addAll(gfg2);
// Printing combined list
print(gfg1);
}
Creating a new list by adding two or more list using addAll() method of list
// Main function
main() {
// Creating lists
List gfg1 = ['Welcome','to'];
List gfg2 = ['GeeksForGeeks'];
// Combining lists
var newgfgList = new List.from(gfg1)..addAll(gfg2);
// Printing combined list
print(newgfgList);
}
Creating a new list by adding two or more list using expand() method of list
// Main function
main() {
// Creating lists
List gfg1 = ['Welcome'];
List gfg2 = ['to'];
List gfg3 = ['GeeksForGeeks'];
// Combining lists
var newgfgList = [gfg1, gfg2, gfg3].expand((x) => x).toList();
// Printing combined list
print(newgfgList);
}
apread运算符: ...
// Main function
main() {
// Creating lists
List gfg1 = ['Welcome'];
List gfg2 = ['to'];
// Combining lists
var newgfgList = [...gfg1, ...gfg2, 'GeeksForGeeks'];
// Printing combined list
print(newgfgList);
}
写这篇, 是有一个需求没有解决, 网上找的替代方案。 dart三目运算符里怎们包起来代码?
var item = [1, 2, 3];
var one = [...item, 4]; // right
var two = [true ? ...item : 4]; // error: Expected an identifier