dart:core库中的List类提供了 replaceRange()函数来修改List元素,此函数替换指定范围内的元素的值。
使用List.replaceRange()函数的语法如下所示-
List.replaceRange(int start_index,int end_index,Iterable <items>)
Start_index - 代表要开始替换的索引位置的整数。
End_index - 表示停止替换的索引位置的整数。
<items> - 代表更新值的可迭代对象。
以下示例说明了相同的内容-
void main() { List l=[1, 2, 3,4,5,6,7,8,9]; print('The value of list before replacing ${l}'); l.replaceRange(0,3,[11,23,24]); print('The value of list after replacing the items between the range [0-3] is ${l}'); }
它应该产生以下输出-
The value of list before replacing [1, 2, 3, 4, 5, 6, 7, 8, 9] The value of list after replacing the items between the range [0-3] is [11, 23, 24, 4, 5, 6, 7, 8, 9]
参考链接
https://www.learnfk.com/dart-programming/dart-programming-list-replacerange-function.html
标签:index,replacing,List,list,无涯,value,Dart,replaceRange From: https://blog.51cto.com/u_14033984/8407901