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"); Iterator<String> nameIterator = names.iterator(); nameIterator.forEachRemaining(System.out::println); }
From source file:Main.java
public static void main(String args[]) { List<Integer> dataList = new ArrayList<Integer>(); for (int i = 0; i < 10; i++) { dataList.add(i);/*from w w w .ja v a 2 s . c o m*/ } Collections.shuffle(dataList); int[] num = new int[dataList.size()]; for (int i = 0; i < dataList.size(); i++) { num[i] = dataList.get(i); } System.out.println(Arrays.toString(num)); }
From source file:Main.java
public static void main(String[] args) { // create a new list of arguments for our process List<String> list = new ArrayList<String>(); list.add("notepad.exe"); // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the command list System.out.println(pb.command()); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("Monday"); list.add("Tuesdag"); list.add("Wednesday"); list.add("Thursday"); list.add("Friday"); list.add("Saturday"); list.add("Sunday"); Iterator<String> iterator = null; iterator = list.iterator();//from w w w . j a v a 2 s. c o m while (iterator.hasNext()) { String element = iterator.next(); System.out.println(element); } for (iterator = list.iterator(); iterator.hasNext();) { String element = iterator.next(); System.out.println(element); } for (String element : list) { System.out.println(element); } }
From source file:Main.java
public static void main(String args[]) { List<Character> list = new ArrayList<Character>(); list.add('X'); System.out.println("Element added to list: " + list.get(0)); Collection<Character> immutableCol = Collections.unmodifiableCollection(list); immutableCol.add('Y'); }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Foo> foos = new ArrayList<>(); IntStream.range(1, 4).forEach(num -> foos.add(new Foo("Foo" + num))); foos.forEach(f -> IntStream.range(1, 4).forEach(num -> f.bars.add(new Bar("Bar" + num + " <- " + f.name)))); foos.stream().flatMap(f -> f.bars.stream()).forEach(b -> System.out.println(b.name)); }
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); // populate the list arlst.add("CSS"); arlst.add("PHP"); arlst.add("HTML"); arlst.add("java2s.com"); // create typesafe view of the collection Collection<String> tslst = Collections.checkedCollection(arlst, String.class); System.out.println(tslst);//from ww w . j a v a 2 s. com }
From source file:Main.java
public static void main(String[] argv) throws Exception { List<Integer> list = new ArrayList<Integer>(); int capacity = 100; ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity); queue.put(0);//from ww w . ja v a 2 s. c o m queue.put(1); queue.put(2); queue.drainTo(list, 3); System.out.println(queue); System.out.println(list); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List<Integer> list = new ArrayList<Integer>(); int capacity = 100; ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity); queue.put(0);// w ww. jav a 2 s. c om queue.put(1); queue.put(2); queue.drainTo(list); System.out.println(queue); System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { List<String> colours = new ArrayList<String>(); colours.add("red"); colours.add("green"); colours.add("blue"); colours.add("yellow"); colours.add("cyan"); colours.add("white"); colours.add("black"); Collections.sort(colours);// w w w. ja va2 s .c o m System.out.println(Arrays.toString(colours.toArray())); Collections.sort(colours, Collections.reverseOrder()); System.out.println(Arrays.toString(colours.toArray())); }