1import java.util.ArrayList;
2import java.util.LinkedList;
3import java.util.List;
4
5class scratch{
6 public static void main(String[] args) {
7 List<Integer> aList = new ArrayList<>();
8 List<Integer> lList = new LinkedList<>();
9 }
10}
1import java.util.ArrayList;
2import java.util.Collections;
3import java.util.List;
4import java.util.ListIterator;
5public class Main {
6 public static void main(String[] args) {
7 List<String> list = new ArrayList<String>();
8 list.add("a");
9 list.add("b");
10 list.add("c");
11 list.add("d");
12 list.add("e");
13 list.add("f");
14
15 //On met la liste dans le désordre
16 Collections.shuffle(list);
17 System.out.println(list);
18
19 //On la remet dans l'ordre
20 Collections.sort(list);
21 System.out.println(list);
22
23 Collections.rotate(list, -1);
24 System.out.println(list);
25
26 //On récupère une sous-liste
27 List<String> sub = list.subList(2, 5);
28 System.out.println(sub);
29 Collections.reverse(sub);
30 System.out.println(sub);
31
32 //On récupère un ListIterator
33 ListIterator<String> it = list.listIterator();
34 while(it.hasNext()){
35 String str = it.next();
36 if(str.equals("d"))
37 it.set("z");
38 }
39 while(it.hasPrevious())
40 System.out.print(it.previous());
41
42 }
43}
44
1boolean add(E e)
2
3Appends the specified element to the end of this list (optional operation).
4
5Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
6
7Specified by:
8 add in interface Collection<E>
9Parameters:
10 e - element to be appended to this list
11Returns:
12 true (as specified by Collection.add(E))
13Throws:
14 UnsupportedOperationException - if the add operation is not supported by this list
15 ClassCastException - if the class of the specified element prevents it from being added to this list
16 NullPointerException - if the specified element is null and this list does not permit null elements
17 IllegalArgumentException - if some property of this element prevents it from being added to this list
1import java.util.*;
2var list = new ArrayList<String>();
3list.add("Hello World!");