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