List of usage examples for java.util List add
boolean add(E e);
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"); // filtering//from w ww .j a v a 2 s . c om stringCollection.stream().filter((s) -> s.startsWith("a")).forEach(System.out::println); }
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");//from w w w . j a v a2 s .co 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> carList = new ArrayList<String>(); carList.add("A"); carList.add("B"); carList.add("C"); carList.add("D"); String[] carArray = carList.toArray(new String[0]); for (String car : carArray) { System.out.println(car);//from w w w. j av a2s.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"); Optional<String> reduced = stringCollection.stream().sorted().reduce((s1, s2) -> s1 + "#" + s2); reduced.ifPresent(System.out::println); }
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"); long startsWithB = stringCollection.stream().filter((s) -> s.startsWith("b")).count(); System.out.println(startsWithB); // 3 }
From source file:MainClass.java
public static void main(String[] args) { List list = new ArrayList(); for (int i = 0; i < 10; i++) list.add(""); Collections.fill(list, "Hello"); System.out.println(list);/*ww w . j a va 2 s .co m*/ }
From source file:Main.java
public static void main(String[] args) { List<String> fruits = new ArrayList<String>(); fruits.add("A"); fruits.add(""); fruits.add("C"); fruits.add("D"); fruits.add("A"); Collator collator = Collator.getInstance(Locale.US); Collections.sort(fruits, collator); for (int i = 0; i < fruits.size(); i++) { String fruit = fruits.get(i); System.out.println("Fruit = " + fruit); }/*from w ww . j ava2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { List<String> theList = new LinkedList<String>(); theList.add("A"); theList.add("B"); theList.add("C"); theList.add("D"); String[] my = theList.toArray(new String[theList.size()]); for (int i = 0; i < my.length; i++) { System.out.println(my[i]); }//from w w w.j a va 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { List<String> theList = new LinkedList<String>(); theList.add("A"); theList.add("B"); theList.add("C"); theList.add("D"); String[] my = theList.toArray(new String[0]); for (int i = 0; i < my.length; i++) { System.out.println(my[i]); }/* w ww. j a v a 2 s. com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url16 = new URL("http://www.java2s.com/style/download.png"); URL url32 = new URL("http://www.java2s.com/style/download.png"); final List<Image> icons = new ArrayList<Image>(); icons.add(ImageIO.read(url16)); icons.add(ImageIO.read(url32)); JFrame f = new JFrame(); f.setIconImages(icons);/*w w w . j a v a 2s . co m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 100); f.setVisible(true); }