List of usage examples for java.util ArrayList ArrayList
public ArrayList()
From source file:Main.java
public static void main(String[] argv) throws Exception { List<String> list1 = new ArrayList(); List<String> list2 = new ArrayList(); list1.addAll(list2);/* ww w.j av a 2 s. c o m*/ list1.removeAll(list2); list1.retainAll(list2); list1.clear(); int newSize = 2; list1.subList(newSize, list1.size()).clear(); }
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(); listIterator.next();//from ww w .ja va 2 s. c o m listIterator.set("100"); for (String str : aList) { System.out.println(str); } }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(new Integer("3")); arrayList.add(new Integer("1")); arrayList.add(new Integer("8")); arrayList.add(new Integer("3")); arrayList.add(new Integer("5")); Object obj = Collections.max(arrayList); System.out.println(obj);//ww w. j av a 2 s . c o m }
From source file:Main.java
public static void main(final String[] args) { List<String> stringCollection = new ArrayList<>(); stringCollection.add("ddd2"); stringCollection.add("aaa2"); stringCollection.add("bbb1"); stringCollection.add("aaa1"); stringCollection.add("bbb3"); stringCollection.add("ccc"); stringCollection.add("bbb2"); stringCollection.add("ddd1"); stringCollection.stream().map(String::toUpperCase).sorted((a, b) -> b.compareTo(a)) .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] argv) { List list = new ArrayList(); int pos = 200; int align = TabStop.ALIGN_RIGHT; int leader = TabStop.LEAD_NONE; TabStop tstop = new TabStop(pos, align, leader); list.add(tstop);/*from www .ja v a 2s.com*/ }
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();/*from ww w. j av a 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) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Oracle"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); int count = list.size(); System.out.println("Size of List: " + count); // Print each element with its index for (int i = 0; i < count; i++) { String element = list.get(i); System.out.println("Index=" + i + ", Element=" + element); }//from w ww .j a v a2 s.c o m List<String> subList = list.subList(1, 3); System.out.println(subList); // Remove "CSS" from the list list.remove("CSS"); // Same as list.remove(2); System.out.println(list); }
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"); List lst = arrayList.subList(1, 3); for (int i = 0; i < lst.size(); i++) System.out.println(lst.get(i)); // remove one element from sub list Object obj = lst.remove(0);//from w ww .jav a 2s . c o m System.out.println(obj + " is removed"); for (String str : arrayList) System.out.println(str); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List list = new ArrayList(); Collections.shuffle(list);/*from ww w . ja va 2 s.c om*/ }
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();/* ww w. j av a2 s .com*/ System.out.println("Previous: " + listIterator.previousIndex()); System.out.println("Next: " + listIterator.nextIndex()); }