List of usage examples for java.util ArrayList add
public boolean add(E e)
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("java2s.com"); ListIterator<String> listIterator = aList.listIterator(); System.out.println("Previous: " + listIterator.previousIndex()); System.out.println("Next: " + listIterator.nextIndex()); // advance current position by one using next method listIterator.next();/* ww w . j ava 2s.c o m*/ System.out.println("Previous: " + listIterator.previousIndex()); System.out.println("Next: " + listIterator.nextIndex()); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(15); arrlist.add(22);/*from w w w . j a v a 2 s . c om*/ arrlist.add(30); arrlist.add(40); System.out.println(arrlist); // retrieves element at 4th postion int retval = arrlist.get(3); System.out.println("Retrieved element is = " + retval); }
From source file:Main.java
public static void main(String args[]) { ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(1); arrlist.add(2);//from w w w . ja va 2s.co m 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: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(); System.out.println("Previous: " + listIterator.previousIndex()); System.out.println("Next: " + listIterator.nextIndex()); // advance current position by one using next method listIterator.next();//from w ww.j a v a 2s .co m System.out.println("Previous: " + listIterator.previousIndex()); System.out.println("Next: " + listIterator.nextIndex()); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(1); arrlist.add(2);/* www.j a v a2s.c o m*/ arrlist.add(2); arrlist.add(2); System.out.println(arrlist); // change element to 55 at 3rd position arrlist.set(2, 55); System.out.println(arrlist); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(10); arrlist.add(12);//from w w w.ja va 2s. com arrlist.add(31); arrlist.add(49); // toArray copies content into other array Integer myArray[] = new Integer[arrlist.size()]; myArray = arrlist.toArray(myArray); System.out.println(Arrays.toString(myArray)); }
From source file:Main.java
public static void main(String args[]) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(1); arrlist.add(2);//from w ww . j av a 2 s.com arrlist.add(3); arrlist.add(4); arrlist.add(5); System.out.println(arrlist); List<Integer> arrlist2 = arrlist.subList(2, 4); System.out.println(arrlist2); }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("1");/* w ww . java 2 s . c o m*/ v.add("2"); v.add("3"); ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("4"); arrayList.add("5"); v.addAll(arrayList); for (int i = 0; i < v.size(); i++) { System.out.println(v.get(i)); } }
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:Main.java
public static void main(String[] args) { ArrayList<String> arrlist = new ArrayList<String>(5); arrlist.add("G"); arrlist.add("E"); arrlist.add("F"); arrlist.add("M"); arrlist.add("from java2s.com"); System.out.println("Size of list: " + arrlist.size()); System.out.println(arrlist);/*from ww w . ja va 2 s . co m*/ // retrieving the index of element "E" int retval = arrlist.indexOf("E"); System.out.println("The element E is at index " + retval); }