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[] a) {

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

    ListIterator iter = list.listIterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from ww w  .ja  v  a 2  s  .c  om*/

}

From source file:Main.java

public static void main(String[] argv) {
    List<String> mascots = new ArrayList<>();
    mascots.add("duke");
    mascots.add("juggy");

    String actual = mascots.stream().reduce((t, u) -> t + "," + u).get();
    System.out.println(actual);//from   w  ww .  j  a  v a2 s .c  o  m
}

From source file:MainClass.java

public static void main(String[] a) {

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

    List list2 = ((List) ((ArrayList) list).clone());

    System.out.println(list);//from  ww  w . j  a va 2 s.c  o  m
    System.out.println(list2);

    list.clear();

    System.out.println(list);
    System.out.println(list2);
}

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 list2 = new ArrayList();
    list2.add("X");
    list2.add("Y");
    list2.add("Z");
    list.addAll(list2);/*from  w w w .j a  v  a  2  s  .c  o m*/
    list.addAll(1, list2);

    System.out.println(list);
}

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());
    }//from   ww w  .  j a v  a2s.  c  o m

}

From source file:Main.java

public static void main(String args[]) {
    List<String> list = new ArrayList<>();
    list.add("java2s.com");
    list.add("java2s.com");
    list.add("java2s.com");

    HashSet<String> hs = new HashSet<String>(list);

    System.out.println(hs);/*from w  ww .  j  a  v a  2s . c  o  m*/
}

From source file:Main.java

public static void main(String[] argv) {
    List<Integer> intlist = new ArrayList<Integer>();

    intlist.add(new Integer(123));
}

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");

    Iterator<String> nameIterator = names.iterator();
    nameIterator.forEachRemaining(System.out::println);
}

From source file:Main.java

public static void main(String[] argv) {

    List<Number> numlist = new ArrayList<Number>();

    numlist.add(new Integer(123));
    numlist.add(new Float(123));
}

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");

    for (String name : names) {
        System.out.println(name);
    }/*w  w w. j a  v  a2s  .com*/

}