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

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

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

    Iterator<Integer> iterator = arrlist.iterator();
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        System.out.println(i);
    }

}

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. ja va 2 s  .c  o m
    list.addAll(1, list2);

    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < 10; i++)
        list.add("");
    Collections.fill(list, "Hello");
    System.out.println(list);//w  ww  .  j ava 2  s.  c o  m
}

From source file:Main.java

public static void main(String[] argv) {
    List list = new ArrayList();
    int pos = 300;
    int align = TabStop.ALIGN_CENTER;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);//from  w w w .  ja v a2  s. c om

}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<String> aList = new ArrayList<String>();

    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    Iterator itr = aList.iterator();

    // iterate through the ArrayList values using Iterator's hasNext and next methods

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/* w  ww .  jav a  2s  .co  m*/
}

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

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

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);/*  w  w w  . ja v a2  s . co m*/
}

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("C");
    arrayList.add("D");
    arrayList.add("E");

    System.out.println(arrayList);
    Collections.swap(arrayList, 0, 4);
    System.out.println(arrayList);
}

From source file:Main.java

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

    ListIterator<String> listIterator = aList.listIterator();

    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//from   w ww  . jav  a 2s .c om
    while (listIterator.hasPrevious()) {
        System.out.println(listIterator.previous());
    }
}

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

    System.out.println(list);
}