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:MainClass.java

public static void main(String args[]) throws Exception {
    // Create/fill collection
    List list = new ArrayList();
    list.add("A");
    list.add("B");
    list.add("C");
    System.out.println(list);/*  w w  w. ja v a2 s .co  m*/
}

From source file:MainClass.java

public static void main(String[] a) {
    List list = new ArrayList();
    list.add("A");
    list.add("C");
    list.add("B");
    Collections.sort(list);/* w  ww . j av  a2 s.  c o m*/
    System.out.println(list);
}

From source file:MainClass.java

public static void main(String[] a) {
    List list = new ArrayList();
    list.add("A");
    list.add("C");
    list.add("B");
    Collections.sort(list, Collections.reverseOrder());
    System.out.println(list);/*www .  ja  v a 2 s  . c  om*/
}

From source file:MainClass.java

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

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

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

}

From source file:Main.java

public static void main(String[] args) {
    List list = new ArrayList();
    list.add("Item 1");
    list.add("Item 2");

    if (list.contains("Item 1")) {
        System.out.println("True");
    } else {//from w  w  w  .ja  v  a 2 s.  c o m
        System.out.println("False");
    }
}

From source file:MainClass.java

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

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

    System.out.println(list);/*from w  ww . j  av  a  2 s .  c om*/

}

From source file:Main.java

public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");

    list.add("java2s.com");

    System.out.println("List has:" + list.size());
}

From source file:MainClass.java

public static void main(String[] args) {
    List myList = new ArrayList();
    myList.add("Hello");
    myList.add("World");
    myList.add("World");
    Set set = new HashSet(myList);

    System.out.println(set);//from   w ww . j  a  va  2s.  co  m
}

From source file:MainClass.java

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

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

    System.out.println(list.remove(0));
    System.out.println(list.remove("B"));
    System.out.println(list);//  w  w w  .j a  va2  s . com

}

From source file:Main.java

public static void main(String[] args) {
    // Create a list of strings
    List<String> names = new ArrayList<>();
    names.add("A");
    names.add("B");
    names.add("C");

    names.forEach(System.out::println);
}