0
Lists
Can we just add item in list manually after creating it like in ArrayLists in java.In java we can use m.add() to add items in an ArrayList named m.
1 Respuesta
+ 1
List is an interface, so you can't instantiate (create object of) it.
However, List interface can be used as a reference type. It has an abstract add() method which ArrayList and several other classes implement.
Ex.
List <String> strings = new ArrayList<>();
strings.add("Lorem");
strings.add("Ipsum");
As you can see, In this code we are referencing ArrayList object through a List interface reference. When you call the add method it actually invokes the overriden version of add method from ArrayList class (not the List interface) at runtime.
List is just abstract description for other classes. List by it self is never instantiated.