If you check the API for List you’ll notice it says:
Interface List
Being an interface means it cannot be instantiated (no new List() is possible).
If you check that link, you’ll find some classes that implement List:
All Known Implementing Classes:
AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector
Those can be instantiated. Use their links to know more about them, I.E: to know which fits better your needs.
The 3 most commonly used ones probably are:
List
List
List
Bonus:
You can also instantiate it with values, in an easier way, using the Arrays class, as follows:
List
System.out.println(supplierNames.get(1));
But note you are not allowed to add more elements to that list, as it’s fixed-size.
Can’t instantiate an interface but there are few implementations:
JDK2
List
JDK7
//diamond operator
List
list.add(“one”);
list.add(“two”);
list.add(“three”);
JDK8
List
JDK9
// creates immutable lists, so you can’t modify such list
List
// if we want mutable list we can copy content of immutable list
// to mutable one for instance via copy-constructor (which creates shallow copy)
List
Plus there are lots of other ways supplied by other libraries like Guava.
List