Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; public class ArrayListAddExample4{ public static void main(String[] args){ List
list = new ArrayList<>(); list.add(0, "e1"); // ["e1"] list.add(1); // ["e1" , 1] list.add(1, "e2"); // ["e1", "e2", 1] list.add(0, 1); // [1, "e1", "e2" , 1] System.out.println(list); // [1, "e1", "e2" , 1] } }
Output