java Android:将项目添加到数组列表的顶部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30733280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:34:43 来源:igfitidea点击:
Android: Add item to top of arraylist
提问by Akshay
I have a ArrayList
of model class with some items in it. How to add new item to first position of ArrayList
and shift others next to it.
我有一个ArrayList
模型类,里面有一些项目。如何将新项目添加到第一个位置ArrayList
并移动它旁边的其他项目。
回答by Krishna V
You can use this method.
您可以使用此方法。
arraylist .add(0, object)
回答by Shai
AbstractList declares the following:
AbstractList 声明如下:
public void add(int location, E object)
So,
所以,
myArrayList.add(0, myObject);
Would add it an the top of the list.
将它添加到列表的顶部。