Initialize a collection

Report a typo

Add one, two, three Strings to the list field in the provided order.

Write a program in Java 17
import java.util.ArrayList;

class Main {
ArrayList<String> list = new ArrayList<>();

void init() {
// add "one", "two", "three" to list field in this order
}
}

class Test {
public static void main(String[] args) {
Main main = new Main();
main.init();

for (String str : main.list) {
System.out.println(str);
}
}
}
___

Create a free account to access the full topic