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.
You can use this method.
arraylist .add(0, object)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With