Dynamic arrays that can grow and shrink.
import java.util.ArrayList;
ArrayList<String> fruits = new ArrayList<>();
ArrayList<String> list = new ArrayList<>();
list.add("Apple"); // Add element
list.add("Banana");
list.get(0); // Get element: "Apple"
list.set(0, "Mango"); // Replace element
list.remove("Banana"); // Remove by value
list.remove(0); // Remove by index
list.size(); // Number of elements
list.clear(); // Remove all
list.contains("Apple"); // Check if exists
for (String item : list) {
System.out.println(item);
}
Interactive Visualization