如何将条目添加到列表中的特定索引? [英] How can i add an entry to a specific index in a list?
本文介绍了如何将条目添加到列表中的特定索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以调用list.add(),它会在末尾添加,但是没有方便的方法可以将条目添加到特定索引中,同时又可以增加列表。
I can call list.add() which adds at the end but there is no convenient way to add an entry to a specific index which at the same time grows the list.
推荐答案
您可以使用 insertRange ,它将在添加新元素时增加列表。
You can use insertRange, it will grow the list when adding new elements.
var list = ["1","3","4"];
list.insertRange(0, 1, "0");
list.insertRange(2, 1, "2");
list.forEach((e) => print(e));
您可以在DartBoard上试用此处
You can try it out on the DartBoard here
这篇关于如何将条目添加到列表中的特定索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文