Collections
Learn how ArrayList can store and manage dynamic collections of objects.
Java Code
Study the example and understand what each part does.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> students =
new ArrayList<>();
students.add("Brian");
students.add("Mary");
students.add("John");
for (String student : students) {
System.out.println(student);
}
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Brian Mary John
Finished this lesson?
Mark it complete to update your course progress.