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<String> arrayList = new ArrayList<String>();

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

    System.out.println(arrayList.contains("2"));

    int index = arrayList.indexOf("4");
    if (index == -1)
        System.out.println("not contain 4");
    else//from ww w .ja  v a  2  s.  co m
        System.out.println("4 at index :" + index);

    int lastIndex = arrayList.lastIndexOf("1");
    if (lastIndex == -1)
        System.out.println("not contain 1");
    else
        System.out.println("Last index :" + lastIndex);
}

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);//from   www .ja va2 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);/*from   www.ja v  a2  s. c  o m*/
}

From source file:NewStyle.java

public static void main(String args[]) {

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

    list.add("one");
    list.add("two");
    list.add("three");
    list.add("four");

    Iterator<String> itr = list.iterator();

    while (itr.hasNext()) {
        String str = itr.next(); // no cast needed

        System.out.println(str + " is " + str.length() + " chars long.");
    }/*  w ww. j  ava2  s . c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
    List list = Collections.synchronizedList(arrayList);
}

From source file:Main.java

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

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

    ArrayList<Integer> anotherList = new ArrayList<Integer>(arrlist);
    System.out.println(anotherList);

}

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

    System.out.println(list.remove(0));
    System.out.println(list.remove("B"));
    System.out.println(list);/*from   ww  w  . j  ava2 s. c  o m*/

}

From source file:Main.java

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

    arrayList.add(new Integer("1"));
    arrayList.add(new Integer("2"));
    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("4"));
    arrayList.add(new Integer("5"));

    Object obj = Collections.min(arrayList);
    System.out.println(obj);//  w  w  w . j  a  va2 s.c  o  m
}

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");
    arrayList.add("4");
    arrayList.add("5");

    Iterator itr = arrayList.iterator();
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/* ww  w.ja  va2 s .  c o m*/
}

From source file:MainClass.java

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