2021-04-27 23:28:23
Dart中List数组的操作
Dart中List的创建
和js中数组和其他语言中的List类似,分为可变长度和固定长度两种,与js不同的是List中的元素可为任意类型也可指定类型...3. insert
向指定位置插入元素
List b = [1,2,3,4]
b.insert(1,9);
print(b);//[1,9,2,3,4]
insertAll
从指定的索引开始插入给定的值列表...120,130,1,2,3]
indexOf
查找指定元素所在位置
List a = [1,2,3,4,5];
print(a.indexOf(2));//输出1
remove
List.remove()函数删除列表中第一次出现的指定项...如果从列表中删除指定的值,则此函数返回true。...int res = l.removeAt(1);
print(res);//输出1
print(l);//[1, 3, 4, 5, 6, 7, 8, 9,1]
removeLast
删除并在返回列表中的最后一个项目