How to work with arraylist in java?
The ArrayList
class provides a resizable array and implements the List interface.
Example:
ArrayList names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.add("Charlie");
System.out.println(names.get(0)); // Outputs: Alice
Solution:
Other ArrayList methods:
names.remove("Bob");
names.size(); // Returns: 2