Check out example codes for "java arraylist add to top". It will help you in understanding the concepts better.

Code Example 1

//create an ArrayList
  ArrayList<String> myList 
                = new ArrayList<String>();
        
//some items to ArrayList
myList.add("One");
myList.add("Two");
myList.add("Three");

/*
* To insert element at beginning of ArrayList
* use add method of ArrayList class with index 0
*/

myList.add(0, "Zero");

Learn ReactJs, React Native from akashmittal.com