The List Interface
The List Interface
// Here's a nondestructive form of this idiom, which produces a
// third List consisting of the second list appended to the first.
List<Type> list3 = new ArrayList<Type>(list1);
list3.addAll(list2); //Here's an example (JDK 8 and later) that aggregates some names into a List:
List<String> list = people.stream()
.map(Person::getName)
.collect(Collectors.toList()); import java.util.*;
public class Shuffle {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
for (String a : args)
list.add(a);
Collections.shuffle(list, new Random());
System.out.println(list);
}
} A List is an ordered Collection (sometimes called a sequence). Lists may contain duplicate elements.
In addition to the operations inherited from Collection, the List interface includes operations for the following: positional access (manipulates elements based on their numerical position in the list, this includes methods such as get, set, add, addAll, and remove); search (searches for a specified object in the list and returns its numerical position, search methods include indexOf and lastIndexOf); iteration (extends Iterator semantics to take advantage of the list's sequential nature, the listIterator methods provide this behavior); range-view (the sublist method performs arbitrary range operations on the list).
Semantic portal