Using sequential implementations and interfaces with Generics
As we have just seen, the best practice for creating a List
will be this:
List<String> moreStuff = new ArrayList<>();
Any valid class type can be used. Once we have elements in our collection, we can access them with the get
method and the subscript:
String orange1 = "Valencia"; String orange2 = "Navel"; List<String> stuff = new ArrayList<>(); stuff.add(orange1); stuff.add(orange2); System.out.printf("Stuff: %s%n", stuff.get(0)); System...