Embed presentation
Download to read offline
![Write a program that uses the ArrayList class and populate it
with a list of your course codes, i.e MIS210, then use the
ArrayList methods described in the example in class to add,
remove, and display information about the ArrayList.
simple example of ArrayList:
package bmarina;
import java.util.ArrayList;
public class ArrayListExample {
public static void main(String[] args) {
ArrayList cityList = new ArrayList();
cityList.add("London");
cityList.add("New York");
cityList.add("Paris");
cityList.add("Toronto");
cityList.add("Hong Kong");
cityList.add("Singapore");
System.out.println("List size is " + cityList.size());
System.out.println("Is Toronto in the list? " +
cityList.contains("Toronto"));
System.out.println("The location of New York in the list is
" + cityList.indexOf("New York"));
System.out.println("Is the list empty? " +
cityList.isEmpty());
cityList.add(2, "Beijin");
System.out.println("List size is " + cityList.size());
System.out.println("The location of Beijin in the list is " +
cityList.indexOf("Beijin"));
cityList.remove("Toronto");
System.out.println("List size is " + cityList.size());
cityList.remove(0);
System.out.println("List size is " + cityList.size());
System.out.println(cityList.toString());
for (int i = cityList.size() - 1; i >= 0 ; i--) {](https://image.slidesharecdn.com/writeaprogramthatusesthearraylistclassandpopulateitwitha-221227042522-df0cea4d/85/Write-a-program-that-uses-the-ArrayList-class-and-populate-it-with-a-docx-1-320.jpg)

The document outlines a program that utilizes the ArrayList class in Java to manage a list of course codes and city names. It demonstrates adding, removing, and displaying elements in the ArrayList. Key methods such as size, contains, indexOf, and isEmpty are showcased through example outputs.
![Write a program that uses the ArrayList class and populate it
with a list of your course codes, i.e MIS210, then use the
ArrayList methods described in the example in class to add,
remove, and display information about the ArrayList.
simple example of ArrayList:
package bmarina;
import java.util.ArrayList;
public class ArrayListExample {
public static void main(String[] args) {
ArrayList cityList = new ArrayList();
cityList.add("London");
cityList.add("New York");
cityList.add("Paris");
cityList.add("Toronto");
cityList.add("Hong Kong");
cityList.add("Singapore");
System.out.println("List size is " + cityList.size());
System.out.println("Is Toronto in the list? " +
cityList.contains("Toronto"));
System.out.println("The location of New York in the list is
" + cityList.indexOf("New York"));
System.out.println("Is the list empty? " +
cityList.isEmpty());
cityList.add(2, "Beijin");
System.out.println("List size is " + cityList.size());
System.out.println("The location of Beijin in the list is " +
cityList.indexOf("Beijin"));
cityList.remove("Toronto");
System.out.println("List size is " + cityList.size());
cityList.remove(0);
System.out.println("List size is " + cityList.size());
System.out.println(cityList.toString());
for (int i = cityList.size() - 1; i >= 0 ; i--) {](https://image.slidesharecdn.com/writeaprogramthatusesthearraylistclassandpopulateitwitha-221227042522-df0cea4d/85/Write-a-program-that-uses-the-ArrayList-class-and-populate-it-with-a-docx-1-320.jpg)
