How to make a new List in Java
List myList = new ArrayList();
or with generics (Java 7 or later)
List<MyType> myList = new ArrayList<>();
or with generics (Old java versions)
List<MyType> myList = new ArrayList<MyType>();
Additionally, if you want to create a list that has things in it (though it will be fixed size):
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
Let me summarize and add something:
1. new ArrayList<String>();2. Arrays.asList("A", "B", "C")
1. Lists.newArrayList("Mike", "John", "Lesly");2. Lists.asList("A","B", new String [] {"C", "D"});
Immutable List
1. Collections.unmodifiableList(new ArrayList<String>(Arrays.asList("A","B")));2. ImmutableList.builder() // Guava .add("A") .add("B").build();3. ImmutableList.of("A", "B"); // Guava4. ImmutableList.copyOf(Lists.newArrayList("A", "B", "C")); // Guava
Empty immutable List
1. Collections.emptyList();2. Collections.EMPTY_LIST;
List of Characters
1. Lists.charactersOf("String") // Guava2. Lists.newArrayList(Splitter.fixedLength(1).split("String")) // Guava
List of Integers
Ints.asList(1,2,3); // Guava