List of usage examples for java.util ArrayList ArrayList
public ArrayList()
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"); names.forEach(System.out::println); }
From source file:MainClass.java
public static void main(String[] args) { List cats = new ArrayList(); for (int i = 0; i < 7; i++) cats.add(new Cat(i)); Iterator e = cats.iterator(); while (e.hasNext()) ((Cat) e.next()).id();/* w w w .ja va 2 s .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("5"); // Get an object of ListIterator using listIterator() method ListIterator listIterator = aList.listIterator(); listIterator.next();/* w w w. j a v a 2 s. co m*/ listIterator.next(); // remove element returned by last next method listIterator.remove(); for (String str : aList) { System.out.println(str); } }
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 a va 2s . c om System.out.println("List: " + list); Collections.reverse(list); System.out.println("List: " + list); }
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); arlst.add("CSS"); arlst.add("HTML"); arlst.add("PHP"); // search the list for key int index = Collections.binarySearch(arlst, "HTML"); System.out.println(index);/* w w w . ja va 2 s .c o m*/ }
From source file:Main.java
public static void main(String args[]) { Collection<String> c = new ArrayList<String>(); PriorityQueue<String> p = new PriorityQueue<String>(c); System.out.println(p);//from ww w . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("C"); list.add("C"); list.add("C"); list.add("C"); list.add("C"); for (Iterator<String> iter = list.iterator(); iter.hasNext();) { String s = iter.next();//from www. ja v a 2s .c om if (s.equals("B")) { iter.remove(); } else { System.out.println(s); } } for (String s : list) { System.out.println(s); } }
From source file:Main.java
public static void main(String[] args) { Collection<String> names = new ArrayList<>(); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); names.add("XML"); names.add("HTML"); names.add("CSS"); System.out.printf("Size = %d, Elements = %s%n", names.size(), names);// www . j a va 2 s . co m names.remove("CSS"); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); names.clear(); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); }
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"); System.out.println("List: " + list); // Uses List.sort() method with a Comparator list.sort(Comparator.comparing(String::length)); System.out.println("Sorted List: " + list); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); // populate the list list.add("1"); list.add("2"); list.add("3"); list.add("4"); list.add("from java2s.com"); // create a synchronized list List<String> synlist = Collections.synchronizedList(list); System.out.println("Sunchronized list is :" + synlist); }