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

    List list2 = new ArrayList();
    list2.add("A");
    list2.add("B");
    list2.add("C");
    list.removeAll(list2);/* ww  w. j a  v a 2s. co  m*/

    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> al = new ArrayList<String>();
    al.add("Java");
    al.add("SQL");
    al.add("Data");

    System.out.println("ArrayList:" + al);
    String[] s1 = new String[al.size()];

    String[] s2 = al.toArray(s1);

    System.out.println("s1 == s2:" + (s1 == s2));
    System.out.println("s1:" + Arrays.toString(s1));
    System.out.println("s2:" + Arrays.toString(s2));

    s1 = new String[1];
    s1[0] = "hello"; // Store hello in first element

    s2 = al.toArray(s1);/*from   w  ww.  ja  v  a 2  s .co  m*/

    System.out.println("s1 == s2:" + (s1 == s2));
    System.out.println("s1:" + Arrays.toString(s1));
    System.out.println("s2:" + Arrays.toString(s2));
}

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

    long startsWithB = stringCollection.stream().filter((s) -> s.startsWith("b")).count();

    System.out.println(startsWithB); // 3

}

From source file:Main.java

public static void main(String[] a) {
    Collection<String> c = new ArrayList<String>();
    c.add("1");// w  ww . j a  v  a 2s  . c  om
    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(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("A");
    list.add("B");
    list.add("B");
    list.add("C");
    list.add("C");

    List<String> list2 = new ArrayList<String>();
    list2.add("A");
    list2.add("B");
    list2.add("C");
    list.removeAll(list2);/*from  w  w  w. ja v  a  2 s  . co  m*/

    System.out.println(list);
}

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");/*  w w w . j  a  va2  s .  c  o  m*/
    v.add("5");

    // append all elements of Vector to ArrayList
    arrayList.addAll(v);

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

}

From source file:Main.java

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

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

    Collections.sort(arrayList);/*from   www  . j a  va 2  s . co m*/

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

From source file:Test.java

public static void main(String[] args) {
    @SuppressWarnings("unchecked")
    List<String> arrayList = new ArrayList();
}

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.shuffle(arrayList);

    System.out.println(arrayList);

}

From source file:MainClass.java

public static void main(String[] a) {
    ArrayList<Employee> emps = new ArrayList<Employee>();
    emps.add(new Employee("A", "G"));
    emps.add(new Employee("T", "A"));
    emps.add(new Employee("K", "J"));

    System.out.println(emps);/*from w w  w  . ja  va  2s.c  o  m*/

    Employee e = emps.get(1);
    e.setLastName("new");

    System.out.println(emps);
}