Sobes.tech
Junior — Middle

Which class in Java is responsible for working with a mutable array of elements?

sobes.tech AI

Answer from AI

In Java, the ArrayList class is used for working with a resizable array of elements. It implements the List interface and allows dynamic resizing of the array, adding, removing, and modifying elements.

Example of using ArrayList:

import java.util.ArrayList;

public class Example {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("First element");
        list.add("Second element");
        list.set(1, "Modified second element");
        list.remove(0);
        System.out.println(list); // Will output: [Modified second element]
    }
}