List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); Object[] array = list.toArray(); for (int i = 0; i < array.length; i++) { System.out.println(array[i].toString()); }/*w w w .j av a 2s . co m*/ }
From source file:Main.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); System.out.println("Initial size of al: " + al.size()); al.add("C");/*w w w. j a v a2s. c om*/ al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add(1, "java2s.com"); System.out.println("Size of al after additions: " + al.size()); System.out.println("Contents of al: " + al); al.remove("F"); al.remove(2); System.out.println("Size of al after deletions: " + al.size()); System.out.println("Contents of al: " + al); }
From source file:MainClass.java
public static void main(String[] a) { List list = new ArrayList(); list.add("A"); List list2 = ((List) ((ArrayList) list).clone()); System.out.println(list);/*from w w w .j av a 2 s . co m*/ System.out.println(list2); list.clear(); System.out.println(list); System.out.println(list2); }
From source file:ArrayListToArray.java
public static void main(String args[]) { ArrayList<Integer> al = new ArrayList<Integer>(); al.add(1);/*ww w .ja v a 2 s. c o m*/ al.add(2); al.add(3); al.add(4); System.out.println("Contents of al: " + al); Integer ia[] = new Integer[al.size()]; ia = al.toArray(ia); int sum = 0; for (int i : ia) sum += i; System.out.println("Sum is: " + sum); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List list = new ArrayList(); Object[] objectArray = list.toArray(); MyClass[] array = (MyClass[]) list.toArray(new MyClass[list.size()]); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> ids = new ArrayList<>(); int total = ids.size(); // total will be zero System.out.println("ArrayList size is " + total); System.out.println("ArrayList elements are " + ids); ids.add(new Integer(10)); // Adding an Integer object. ids.add(20); // Autoboxing ids.add(30); // Autoboxing total = ids.size(); // total will be 3 System.out.println("ArrayList size is " + total); System.out.println("ArrayList elements are " + ids); ids.clear();//from w w w .j a v a 2 s .c o m total = ids.size(); // total will be 0 System.out.println("ArrayList size is " + total); System.out.println("ArrayList elements are " + ids); }
From source file:Main.java
public static void main(String[] a) { List<String> list = new ArrayList<String>(); list.add("A"); List list2 = ((List) ((ArrayList) list).clone()); System.out.println(list);/* ww w.j a va2 s.c om*/ System.out.println(list2); list.clear(); System.out.println(list); System.out.println(list2); }
From source file:OldStyle.java
public static void main(String args[]) { ArrayList list = new ArrayList(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); Iterator itr = list.iterator(); while (itr.hasNext()) { String str = (String) itr.next(); // explicit cast needed here. System.out.println(str + " is " + str.length() + " chars long."); }//from w w w. j a v a 2 s .c o m }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("notepad.exe"); ProcessBuilder pb = new ProcessBuilder(list); List<String> list2 = new ArrayList<String>(); list2.add("text.txt"); // set the command list pb.command(list2);//from ww w . j av a 2 s. c o m System.out.println(pb.command()); }
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"); System.out.println(list.get(2)); }