Adds an element to the list.
Listlist = new ArrayList<>(); list.add("Java"); list.add("Python");
Inserts the element at the specified position.
list.add(1, "C++");
Returns the element at the specified index.
System.out.println(list.get(0)); // Java
Removes the element at the specified index.
list.remove(1); // Removes C++
Removes the first occurrence of the specified element.
list.remove("Python");
Returns the number of elements in the list.
System.out.println(list.size()); // 1
Returns true if the list contains the specified element.
System.out.println(list.contains("Java")); // true
Returns true if the list has no elements.
System.out.println(list.isEmpty()); // false
Removes all elements from the list.
list.clear();
Returns the index of the first occurrence of the element.
list.add("Python");
list.add("Java");
System.out.println(list.indexOf("Java")); // 1
Returns the index of the last occurrence of the element.
System.out.println(list.lastIndexOf("Java")); // 1
Replaces the element at the specified position.
list.set(0, "C#");