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[]) {

    List<String[]> left = new ArrayList<String[]>();
    left.add(new String[] { "one", "two" });

    List<String[]> right = new ArrayList<String[]>();
    right.add(new String[] { "one", "two" });

    java.util.Iterator<String[]> leftIterator = left.iterator();
    java.util.Iterator<String[]> rightIterator = right.iterator();
    if (left.size() != right.size()) {
        System.out.println("not equal");
    }//w ww  . ja va2s.c om
    while (leftIterator.hasNext()) {
        if (Arrays.equals(leftIterator.next(), rightIterator.next()))
            continue;
        else {
            System.out.print("not equal");
            break;
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> myList = new ArrayList<String>();
    myList.add("Hello");
    myList.add("World");
    myList.add("World");
    Set<String> set = new HashSet<String>(myList);

    System.out.println(set);/*from w  w  w  .jav a 2  s .c  om*/
}

From source file:Main.java

public static void main(String[] argv) {
    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("2");
    list.add("c2");

    System.out.println(countDistinctElements(list, 0, list.size()));
}

From source file:Main.java

public static void main(String[] args) {
    List<String> l1 = new ArrayList<String>();
    List<String> l2 = new ArrayList<String>();
    l1.add("a");/*ww  w  .  j a  v  a2 s  .  co m*/
    l1.add("b");
    l1.add("c");

    l2.add("b");
    l2.add("c");
    l2.add("a");

    if (isSorted(l1)) {
        System.out.println("already sorted");
    } else {
        Collections.sort(l1);
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> myList = new ArrayList<String>();
    myList.add("Hello");
    myList.add(0, "World");
    myList.add("java2s.com");
    Set<String> set = new HashSet<String>(myList);

    System.out.println(set);/*from  w ww  .  j a v  a 2  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");

    ListIterator itr = arrayList.listIterator();
    System.out.println("in forward direction");
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/* w  w  w.  j a va  2 s  .c  o  m*/

    System.out.println("in backward direction");
    while (itr.hasPrevious()) {
        System.out.println(itr.previous());
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    list.add("Oracle");
    list.add("SQL");
    list.add("CSS");
    list.add("XML");
    System.out.println("List: " + list);
    // Get the list iterator
    ListIterator<String> iterator = list.listIterator();
    while (iterator.hasNext()) {
        int index = iterator.nextIndex();
        String element = iterator.next();
        System.out.println("Index=" + index + ", Element=" + element);
    }//from w w  w.j  av  a 2s.  com
    // Reuse the iterator to iterate from the end to the beginning
    while (iterator.hasPrevious()) {
        int index = iterator.previousIndex();
        String element = iterator.previous();
        System.out.println("Index=" + index + ",  Element=" + element);
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> aList = new ArrayList<String>();
    Map<Integer, String> aMap = new HashMap<Integer, String>();
    aList.add("A");
    aList.add("B");

    for (int i = 0; i < aList.size(); i++) {
        aMap.put(i + 1, aList.get(i));/*ww  w  . j a  va 2 s  .com*/
    }

    System.out.println(aMap.toString());
}

From source file:Main.java

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

    Set<String> mySet = new HashSet<String>(myList);

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

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

    Enumeration e = Collections.enumeration(arrayList);

    while (e.hasMoreElements())
        System.out.println(e.nextElement());
}