List of usage examples for java.util List add
boolean add(E e);
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"); System.out.println(list.remove(0)); System.out.println(list.remove("B")); System.out.println(list);/* www . ja v a 2s .com*/ }
From source file:Main.java
public static void main(String[] args) { List<String> myList = new ArrayList<String>(); myList.add("Hello"); myList.add("World"); myList.add("World"); Set<String> set = new HashSet<String>(myList); System.out.println(set);//ww w.j a va 2 s. c o m }
From source file:Main.java
public static void main(String[] args) { List<String> myList = new ArrayList<String>(); myList.add("Hello"); myList.add(0, "World"); myList.add("java2s.com"); Set<String> set = new HashSet<String>(myList); System.out.println(set);//from w ww . ja va2 s .c o m }
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);/*from w ww .ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) { List<String> list = new ArrayList<String>(); list.add("A"); list.add("2"); list.add("c2"); System.out.println(countDistinctElements(list, 0, list.size())); }
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<>(); list.add("Java"); list.add("R"); list.add("CSS"); list.add("XML"); Collections.sort(list);/* w ww . ja v a 2s . c om*/ System.out.println("List: " + list); // Rotate elements by 2 Collections.rotate(list, 2); System.out.println("After Rotating by 2: " + list); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("J"); list.add("R"); list.add("C"); list.add("X"); System.out.println("List: " + list); // Uses Comparable implementation in String class // to sort the list in natural order Collections.sort(list);//w w w . j ava 2 s .c o m System.out.println("Sorted List: " + list); }
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 w w . j a va 2 s . c o m System.out.println("List: " + list); Collections.shuffle(list); System.out.println("List: " + list); Collections.shuffle(list); System.out.println("List: " + list); }
From source file:Main.java
public static void main(String[] args) { List<String> strings = new LinkedList<>(); strings.add("a"); strings.add("B"); strings.add("ab"); strings.add("abc"); strings.add("ABC"); ConcurrentMap<Integer, List<String>> byLength = strings.parallelStream() .collect(Collectors.groupingByConcurrent(String::length)); System.out.println(byLength); }