List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); arlst.add("A"); arlst.add("B"); arlst.add("C"); arlst.add("from java2s.com"); // create typesafe view of the list List<String> tslst = Collections.checkedList(arlst, String.class); System.out.println(tslst);/*from w w w . jav a 2s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); Collections.sort(list);// w w w. j a v a2 s.com System.out.println("List: " + list); // Rotate elements by 2 Collections.rotate(list, 2); System.out.println("After Rotating by 2: " + list); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("J"); list.add("R"); list.add("C"); list.add("X"); System.out.println("List: " + list); // Uses Comparable implementation in String class // to sort the list in natural order Collections.sort(list);//from www . j a v a 2 s . c o m System.out.println("Sorted List: " + list); }
From source file:Main.java
public static void main(String[] args) { // Create a list of strings List<String> names = new ArrayList<>(); names.add("A"); names.add("B"); names.add("C"); for (String name : names) { System.out.println(name); }//from w ww . jav a2 s. c o m }
From source file:ArrayListExample.java
public static void main(String[] args) { ArrayList<Integer> al = new ArrayList<Integer>(); al.add(new Integer(1)); al.add(new Integer(2)); al.add(new Integer(3)); al.add(new Integer(4)); al.add(new Integer(5)); al.add(new Integer(6)); al.add(new Integer(7)); al.add(new Integer(8)); al.add(new Integer(9)); al.add(new Integer(10)); al.set(5, new Integer(66)); for (Iterator i = al.iterator(); i.hasNext();) { Integer integer = (Integer) i.next(); System.out.println(integer); }/*from www . ja v a 2s.c o m*/ }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); Collections.sort(list);// www.j av a2s .c om System.out.println("List: " + list); Collections.shuffle(list); System.out.println("List: " + list); Collections.shuffle(list); System.out.println("List: " + list); }
From source file:MainClass.java
public static void main(String[] a) { ArrayList<Employee> emps = new ArrayList<Employee>(); Employee emp1 = new Employee("A", "G"); Employee emp2 = new Employee("T", "A"); Employee emp3 = new Employee("K", "J"); emps.add(emp1);//from w w w . j ava2 s . c om emps.add(emp2); emps.add(emp3); System.out.println(emps); emps.remove(emp2); System.out.println(emps); }
From source file:Main.java
public static void main(String[] args) { List<String> arrayList = new ArrayList<String>(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); Vector<String> v = new Vector<String>(); v.add("4");// ww w . j ava 2 s . c o m v.add("5"); // insert all elements of Vector to ArrayList at index 1 arrayList.addAll(1, v); for (String str : arrayList) System.out.println(str); }
From source file:Main.java
public static void main(String args[]) { List<String> arrlist = new ArrayList<String>(); arrlist.add("A"); arrlist.add("B"); arrlist.add("C"); arrlist.add("from java2s.com"); System.out.println(arrlist);/*from www . j av a 2 s.co m*/ // add values to this collection boolean b = Collections.addAll(arrlist, "1", "2", "3"); System.out.println(arrlist); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { // Create/fill collection List list = new ArrayList(); list.add("A"); list.add("B"); list.add("C"); System.out.println(list);//from w w w. jav a 2 s. co m }