If you check the API for List you'll notice it says:
Interface List<E>
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
Some of those can be instantiated (the ones that are not defined as abstract class). 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<String> supplierNames1 = new ArrayList<String>();
List<String> supplierNames2 = new LinkedList<String>();
List<String> supplierNames3 = new Vector<String>();
Bonus:
You can also instantiate it with values, in an easier way, using the Arrays class, as follows:
List<String> supplierNames = Arrays.asList("sup1", "sup2", "sup3");
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<String> list = Arrays.asList("one", "two", "three");
JDK7
//diamond operator
List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
JDK8
List<String> list = Stream.of("one", "two", "three").collect(Collectors.toList());
JDK9
// creates immutable lists, so you can't modify such list
List<String> immutableList = List.of("one", "two", "three");
// 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<String> mutableList = new ArrayList<>(List.of("one", "two", "three"));
Plus there are lots of other ways supplied by other libraries like Guava.
List<String> list = Lists.newArrayList("one", "two", "three");
There are various options. Personally I like using Guava:
List<String> strings = Lists.newArrayList("s1", "s2", "s3");
(Guava's a library worth having anyway, of course :)
Using just the JDK, you could use:
List<String> strings = Arrays.asList("s1", "s2", "s3");
Note that this will return an ArrayList, but that's not the normal java.util.ArrayList - it's an internal one which is mutable but fixed-size.
Personally I prefer the Guava version as it makes it clear what's going on (the list implementation which will be returned). It's also still clear what's going on if you statically import the method:
// import static com.google.common.collect.Lists.newArrayList;
List<String> strings = newArrayList("s1", "s2", "s3");
... whereas if you statically import asList it looks a little odder.
Another Guava option, if you don't want a modifiable-in-any-way list:
ImmutableList<String> strings = ImmutableList.of("s1", "s2", "s3");
I typically want to either have a completely mutable list (in which case Lists.newArrayList is best) or a completely immutable list (in which case ImmutableList.of is best). It's rare that I really want a mutable-but-fixed-size list.
Java 9+
Java 9 introduces a convenience method List.of used as follows:
List<String> l = List.of("s1", "s2", "s3");
Java 8 and older
Here are a few alternatives:
// Short, but the resulting list is fixed size.
List<String> list1 = Arrays.asList("s1", "s2", "s3");
// Similar to above, but the resulting list can grow.
List<String> list2 = new ArrayList<>(Arrays.asList("s1", "s2", "s3"));
// Using initialization block. Useful if you need to "compute" the strings.
List<String> list3 = new ArrayList<String>() {{
add("s1");
add("s2");
add("s3");
}};
When it comes to arrays, you could initialize it at the point of declaration like this:
String[] arr = { "s1", "s2", "s3" };
If you need to reinitialize it or create it without storing it in a variable, you do
new String[] { "s1", "s2", "s3" }
If the string constants are may though, it would look like
String[] arr = { "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10",
"s11", "s12", "s13" };
In these cases I usually prefer writing
String[] arr = "s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13".split(",");