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() 

Source Link

Document

Constructs an empty list with an initial capacity of ten.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    Collection c = new ArrayList();
    c.add("1");//  www. j  a v a 2  s .  c  o  m
    c.add("2");
    c.add("3");
    Iterator i = c.iterator();
    while (i.hasNext()) {
        System.out.println(i.next());
    }
}

From source file:Main.java

public static void main(final String[] args) {
    List<String> stringCollection = new ArrayList<>();
    stringCollection.add("ddd2");
    stringCollection.add("aaa2");
    stringCollection.add("bbb1");
    stringCollection.add("aaa1");
    stringCollection.add("bbb3");
    stringCollection.add("ccc");
    stringCollection.add("bbb2");
    stringCollection.add("ddd1");

    boolean noneStartsWithZ = stringCollection.stream().noneMatch((s) -> s.startsWith("z"));

    System.out.println(noneStartsWithZ); // true
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("A");
    arrayList.add("C");
    arrayList.add("D");

    System.out.println(arrayList);

    Collections.replaceAll(arrayList, "A", "Replace All");

    System.out.println(arrayList);
}

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);// w w  w  .j  av  a  2s . c  om

    System.out.println(list);
}

From source file:Main.java

public static void main(final String[] args) {
    List<String> stringCollection = new ArrayList<>();
    stringCollection.add("ddd2");
    stringCollection.add("aaa2");
    stringCollection.add("bbb1");
    stringCollection.add("aaa1");
    stringCollection.add("bbb3");
    stringCollection.add("ccc");
    stringCollection.add("bbb2");
    stringCollection.add("ddd1");

    boolean anyStartsWithA = stringCollection.stream().anyMatch((s) -> s.startsWith("a"));

    System.out.println(anyStartsWithA); // true
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    Vector<String> v = new Vector<String>();
    v.add("4");/*from   w  ww.j av a 2 s  . c o m*/
    v.add("5");

    // insert all elements of Vector to ArrayList at index 1
    arrayList.addAll(1, v);

    for (String str : arrayList)
        System.out.println(str);
}

From source file:Main.java

public static void main(final String[] args) {
    List<String> stringCollection = new ArrayList<>();
    stringCollection.add("ddd2");
    stringCollection.add("aaa2");
    stringCollection.add("bbb1");
    stringCollection.add("aaa1");
    stringCollection.add("bbb3");
    stringCollection.add("ccc");
    stringCollection.add("bbb2");
    stringCollection.add("ddd1");

    boolean allStartsWithA = stringCollection.stream().allMatch((s) -> s.startsWith("a"));

    System.out.println(allStartsWithA); // false
}

From source file:Main.java

public static void main(final String[] args) {
    List<String> stringCollection = new ArrayList<>();
    stringCollection.add("ddd2");
    stringCollection.add("aaa2");
    stringCollection.add("bbb1");
    stringCollection.add("aaa1");
    stringCollection.add("bbb3");
    stringCollection.add("ccc");
    stringCollection.add("bbb2");
    stringCollection.add("ddd1");

    // filtering//from   w  w  w. j  av  a 2 s.  co  m

    stringCollection.stream().filter((s) -> s.startsWith("a")).forEach(System.out::println);
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);/*from   www .j  a v a  2  s .c  o  m*/
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    ListIterator<Integer> iterator = arrlist.listIterator(2);
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        iterator.remove();

    }
    System.out.println(arrlist);

}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);//from  ww  w .  j  a  va2s . c  o  m
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    ListIterator<Integer> iterator = arrlist.listIterator();
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        iterator.remove();

    }
    System.out.println(arrlist);

}