Android: Add item to top of arraylist

18.6k views Asked by At

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.

2

There are 2 answers

1
Krishna V On BEST ANSWER

You can use this method.

arraylist .add(0, object)
0
Shai On

AbstractList declares the following:

public void add(int location, E object)

So,

myArrayList.add(0, myObject);

Would add it an the top of the list.