Java Part 3 - missing step in collections section

Hi,
in a video number 7 in collections section, you did not record creation of class ListDemo.

Slavimir

The ListDemo class was part of the source code provided by the course which is probably why there is no video where Mosh creates the class.

Since it is such a trivial demonstration of how to use collections I will reproduce it here:

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListDemo {
  public static void show() {
    List<String> list = new ArrayList<>();
    list.add("a");
    list.add("b");
    list.add("c");

    // Add an item at a given index
    list.add(0, "!");

    // We can add multiple items in one go
    Collections.addAll(list, "a", "b", "c");

    var first = list.get(0);
    list.set(0, "!!");

    list.remove(0);

    var index = list.indexOf("a");
    var lastIndex = list.lastIndexOf("a");

    System.out.println(list.subList(0, 2));
  }
}
1 Like

Also…