Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

In this page you can find the example usage for java.util List addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List<String> sortedList = new LinkedList<String>();
    sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));

    int index = Collections.binarySearch(sortedList, "c");

    index = Collections.binarySearch(sortedList, "cc");
}

From source file:Main.java

public static void main(String[] argv) {

    List<String> sortedList = new LinkedList<String>();
    sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));

    int index = Collections.binarySearch(sortedList, "c");
    System.out.println(index);//from  w ww  .  j  a v a2s .co m
    index = Collections.binarySearch(sortedList, "e");
    System.out.println(index);
}

From source file:Main.java

public static void main(String[] argv) {

    List<String> sortedList = new LinkedList<String>();
    sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));

    int index = Collections.binarySearch(sortedList, "c");
    System.out.println(index);/*from  w w  w  .  j a va2  s.c  o m*/

    index = Collections.binarySearch(sortedList, "e");
    System.out.println(index);
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> m1 = new LinkedHashMap<String, String>();
    m1.put("1", "One");
    m1.put("3", "Three");

    Map<String, String> m2 = new LinkedHashMap<String, String>();
    m2.put("2", "Two");
    m2.put("4", "Four");

    List<String> list = new ArrayList<String>();
    list.addAll(m1.keySet());
    list.addAll(m2.keySet());//from w w w.j  a  v  a  2s . co  m
    for (String s : list) {
        System.out.println(s);
    }
}

From source file:Main.java

public static void main(String args[]) {
    String a[] = { "a", "b", "c" };
    String b[] = { "d", "e" };

    List<String> list = new ArrayList<String>(Arrays.asList(a));
    list.addAll(Arrays.asList(b));

    Object[] c = list.toArray();//w w w  .  j  a va2 s .co  m
    System.out.println(Arrays.toString(c));
}

From source file:Main.java

public static void main(String... args) {
    List<Apple> inventory = new ArrayList<>();
    inventory.addAll(Arrays.asList(new Apple(80, "green"), new Apple(155, "green"), new Apple(120, "red")));

    inventory.sort((a1, a2) -> a1.getWeight().compareTo(a2.getWeight()));
    System.out.println(inventory);
}

From source file:Main.java

public static void main(String... args) {
    List<Apple> inventory = new ArrayList<>();
    inventory.addAll(Arrays.asList(new Apple(80, "green"), new Apple(155, "green"), new Apple(120, "red")));

    inventory.sort(comparing(Apple::getWeight));
    System.out.println(inventory);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List list1 = new ArrayList();
    List list2 = new ArrayList();

    list1.addAll(list2);

    list1.removeAll(list2);//from ww w . j a  v  a2  s .  com

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
}

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);

    list1.removeAll(list2);/*from w  w w .  ja v a  2  s  .c o m*/

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    int howManyWords = 2;
    List<String> listOfWords = new ArrayList<>();
    Random random = new Random();
    listOfWords.addAll(Arrays.asList(randomMessages));
    List<String> selectedRandomMessages = new ArrayList<>();
    for (int i = 0; i < howManyWords; i++) {
        int randomNumber = random.nextInt(listOfWords.size());
        String randomItem = listOfWords.get(randomNumber);
        selectedRandomMessages.add(randomItem);
        listOfWords.remove(randomItem);//from  www .j  a v  a 2 s. com
    }
    System.out.println(selectedRandomMessages);
}