Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

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

Prototype

public ArrayList(Collection<? extends E> c) 

Source Link

Document

Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:Main.java

public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.add("Hello");
    queue.add("World");
    List<String> list = new ArrayList<String>(queue);

    System.out.println(list);/*from  w w w .j  av a2  s . c  o m*/
}

From source file:Main.java

public static void main(String args[]) {
    String init[] = { "One", "Two", "Three", "One", "Two", "Three" };

    // create two lists
    List<String> list1 = new ArrayList<String>(Arrays.asList(init));
    List<String> list2 = new ArrayList<String>(Arrays.asList(init));

    // remove from list1
    list1.remove("One");
    System.out.println("List1 value: " + list1);

    // remove from list2 using singleton
    list2.removeAll(Collections.singleton("One"));
    System.out.println("The SingletonList is :" + list2);
}

From source file:Main.java

public static void main(String args[]) {

    String init[] = { "One", "Two", "Three", "One", "from java2s.com", "Three" };

    // create one list
    List<String> list = new ArrayList<String>(Arrays.asList(init));

    System.out.println("List value before: " + list);

    // sort the list
    Collections.sort(list);/*from w  w w  .  j  a v a2 s  .  co  m*/

    System.out.println("List value after sort: " + list);
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> linkedList = new LinkedList<String>();
    linkedList.push("A");
    linkedList.push("B");
    linkedList.push("C");
    linkedList.push("D");

    ArrayList<String> arrayList = new ArrayList<String>(linkedList);

    for (String s : arrayList) {
        System.out.println("s = " + s);
    }//  ww  w. jav a2 s.  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    for (int i = 0; i < list.size(); i++) {
        Object o = list.get(i);/*from  ww w .  j a  va 2 s.  com*/
        System.out.println("Object = " + o);
    }
}

From source file:Main.java

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

    List<String> myList = new ArrayList<String>(myQueue);

    for (Object theFruit : myList)
        System.out.println(theFruit);
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
    List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray));

    List<Integer> serialStorage = new ArrayList<>();

    System.out.println("Serial stream:");
    listOfIntegers.stream()//www . j ava 2  s  . com

            // Don't do this! It uses a stateful lambda expression. 
            .map(e -> {
                serialStorage.add(e);
                return e;
            })

            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println("");

    serialStorage.stream().forEachOrdered(e -> System.out.print(e + " "));
    System.out.println("");

    System.out.println("Parallel stream:");
    List<Integer> parallelStorage = Collections.synchronizedList(new ArrayList<>());
    listOfIntegers.parallelStream()

            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })

            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println("");

    parallelStorage.stream().forEachOrdered(e -> System.out.print(e + " "));
    System.out.println("");

}

From source file:Main.java

public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    Object[] objects = list.toArray();

    for (int i = 0; i < objects.length; i++) {
        Object object = objects[i];
        System.out.println("Object = " + object);
    }//from   w ww.j  a v  a 2 s  .  co m
}

From source file:MainClass.java

public static void main(String args[]) {
    String init[] = { "One", "Two", "Three", "One", "Two", "Three" };
    List list1 = new ArrayList(Arrays.asList(init));
    List list2 = new ArrayList(Arrays.asList(init));
    list1.remove("One");
    System.out.println(list1);/* w w w.  j  a  v a2s.  c  o  m*/
    list2.removeAll(Collections.singleton("One"));
    System.out.println(list2);
}

From source file:Main.java

public static void main(String[] args) {
    Queue<String> myQueue = new LinkedList<String>();
    myQueue.add("A");
    myQueue.add("B");
    myQueue.add("C");
    myQueue.add("D");

    List<String> myList = new ArrayList<String>(myQueue);

    for (Object theFruit : myList)
        System.out.println(theFruit);
}