Android: Add item to top of arraylist

18.7k 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 best solutions below

1
On BEST ANSWER

You can use this method.

arraylist .add(0, object)
0
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.