List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrayList1 = new ArrayList<String>(); arrayList1.add("1"); arrayList1.add("2"); arrayList1.add("3"); ArrayList<String> arrayList2 = new ArrayList<String>(); arrayList2.add("One"); arrayList2.add("Two"); arrayList2.add("Three"); arrayList2.add("Four"); arrayList2.add("Five"); System.out.println(arrayList2); Collections.copy(arrayList2, arrayList1); System.out.println(arrayList2); }
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 ww .j av a2 s. co m*/ System.out.println("List: " + list); int index = Collections.binarySearch(list, "CSS"); System.out.println("CSS in List is at " + index); index = Collections.binarySearch(list, "Javascript"); System.out.println("Javascript in List is at " + index); }
From source file:Main.java
public static void main(String[] args) { Collection<Integer> list = new ArrayList<Integer>(); list.add(9);/*from ww w . j a v a 2 s . com*/ Vector vec = new Vector(list); vec.add(4); vec.add(3); vec.add(2); vec.add(1); System.out.println(vec); }
From source file:Main.java
public static void main(String[] argv) { List<String> arrayList1 = new ArrayList<String>(); arrayList1.add("A"); arrayList1.add("A"); arrayList1.add("B"); arrayList1.add("B"); arrayList1.add("B"); arrayList1.add("C"); HashSet<String> hashSet = new HashSet<String>(arrayList1); List<String> arrayList2 = new ArrayList<String>(hashSet); for (Object item : arrayList2) System.out.println(item); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List<Integer> list = new ArrayList<Integer>(); for (int i = 1; i <= 12; i++) list.add(new Integer(i)); Collections.shuffle(list);/*from w w w . j a v a 2s. c om*/ System.out.println(list); }
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"); for (String str : aList) { System.out.println(str);//from w ww.j av a2 s . c om } Iterator itr = aList.iterator(); // remove 2 from ArrayList using Iterator's remove method. String strElement = ""; while (itr.hasNext()) { strElement = (String) itr.next(); if (strElement.equals("2")) { itr.remove(); break; } } for (String str : aList) { System.out.println(str); } }
From source file:Main.java
public static void main(String args[]) { // create an empty array list ArrayList<StringBuilder> arrlist1 = new ArrayList<StringBuilder>(); // use add for new value arrlist1.add(new StringBuilder("from java2s.com")); // using clone to affect the objects pointed to by the references. ArrayList arrlist2 = (ArrayList) arrlist1.clone(); // appending the string StringBuilder strbuilder = arrlist1.get(0); strbuilder.append("tutorials"); System.out.println(arrlist1); System.out.println(arrlist2); }
From source file:MainClass.java
public static void main(String[] args) { List myList = new ArrayList(); myList.add("Hello"); myList.add("World"); myList.add("World"); Set set = new HashSet(myList); System.out.println(set);//from ww w. j av a2 s . c om }
From source file:CompTest.java
public static void main(String args[]) { ArrayList u2 = new ArrayList(); u2.add("Beautiful Day"); u2.add("Stuck In A Moment You Can't Get Out Of"); u2.add("Elevation"); u2.add("Walk On"); u2.add("Kite"); u2.add("In A Little While"); u2.add("Wild Honey"); u2.add("Peace On Earth"); u2.add("When I Look At The World"); u2.add("New York"); u2.add("Grace"); Comparator comp = Comparators.stringComparator(); Collections.sort(u2, comp);//from w ww . j a v a 2 s . c o m System.out.println(u2); Arrays.sort(args, comp); System.out.print("["); for (int i = 0, n = args.length; i < n; i++) { if (i != 0) System.out.print(", "); System.out.print(args[i]); } System.out.println("]"); }
From source file:Main.java
public static void main(String args[]) throws Exception { List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list = Collections.unmodifiableList(list); list.add(1, "G"); System.out.println(list);/* w ww . jav a 2 s . c o m*/ }