Example usage for java.util List add

List of usage examples for java.util List add

Introduction

In this page you can find the example usage for java.util List add.

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) {
    List<Integer> list = new LinkedList<Integer>();
    list.add(1);
    List<Integer> unmodifiableList = Collections.unmodifiableList(list);
    System.out.println(unmodifiableList.getClass());
    if (unmodifiableList.getClass().getName().contains("UnmodifiableList"))
        System.out.println(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.clear();//w w w. j  a v a2s  .c o  m

    System.out.println(list);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    List list = new ArrayList();
    list.add("A");
    list.add("A");
    list.add("B");
    list.add("B");
    list.add("C");
    list.add("C");

    List list2 = new ArrayList();
    list2.add("A");
    list2.add("B");
    list2.add("C");
    list.removeAll(list2);/*from   w ww .j a va  2s .co m*/

    System.out.println(list);
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");

    System.out.println(list.get(2));

}

From source file:MainClass.java

public static void main(String[] a) {

    List list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
        iter.add("a");
        break;/*  ww w .  java  2s.c  o m*/
    }
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) {
    List ls = new ArrayList();
    ls.add(1);
    ls.add(1);/*from w  w  w . j a  va  2 s  .  com*/
    ls.add(2);
    ls.add(5);
    ls.add(4);
    ls.add(4);

    TreeSet s1 = copySet(ls);
    System.out.println(ls);
    System.out.println(s1);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    List list = new ArrayList();
    list.add("A");
    list.add("A");
    list.add("B");
    list.add("B");
    list.add("C");
    list.add("C");
    list.add("D");

    List list2 = new ArrayList();
    list2.add("A");
    list2.add("B");
    list2.add("C");
    list.removeAll(list2);/*from w ww . j a v  a 2 s .co  m*/

    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    list.add("Java");
    list.add("R");
    list.add("CSS");
    list.add("XML");

    Collections.sort(list);/* www  .ja  v a 2 s .com*/
    System.out.println("List: " + list);

    Collections.reverse(list);
    System.out.println("List: " + list);

}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> l = new ArrayList<Integer>();
    l.add(3);
    l.add(2);/*from ww w . j a  v a  2 s.  c  o  m*/
    l.add(1);
    l.add(4);
    l.removeIf(i -> {
        return i >= 3;//No return statement will break compilation
    });
    System.out.println(l);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    Object[] array = list.toArray();
    for (int i = 0; i < array.length; i++) {
        System.out.println(array[i].toString());
    }//from w w w . j a  va2s .  c  o  m
}