Example usage for java.util List add

List of usage examples for java.util List add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:Main.java

public static void main(String args[]) {
    List<String> arrlist = new ArrayList<String>();

    arrlist.add("A");
    arrlist.add("B");
    arrlist.add("C");
    arrlist.add("from java2s.com");

    System.out.println(arrlist);/* w w w. j  a  v a2 s .c  o  m*/

    // add values to this collection
    boolean b = Collections.addAll(arrlist, "1", "2", "3");

    System.out.println(arrlist);
}

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

    stringCollection.stream().map(String::toUpperCase).sorted((a, b) -> b.compareTo(a))
            .forEach(System.out::println);
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("A");
    list.add("B");
    list.add("B");
    list.add("C");
    list.add("C");

    List<String> list2 = new ArrayList<String>();
    list2.add("A");
    list2.add("B");
    list2.add("C");
    list.removeAll(list2);/*from w w w. jav a2  s  . c  o  m*/

    System.out.println(list);
}

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");
    list.add("test.txt");

    // create the process builder
    ProcessBuilder pb = new ProcessBuilder(list);
    try {//from w  ww  .  ja v a2 s . c  o m
        // start the subprocess
        System.out.println("Starting the process..");
        pb.start();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:StringBuilderTester.java

public static void main(String[] args) {
    List list = new ArrayList();
    list.add("I");
    list.add("play");
    list.add("Bourgeois");
    list.add("guitars");
    list.add("and");
    list.add("Huber");
    list.add("banjos");

    System.out.println(StringBuilderTester.appendItems(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 ww .j  a  v a 2 s  . c  om*/
    System.out.println(Arrays.toString(colours.toArray()));

    Collections.sort(colours, Collections.reverseOrder());
    System.out.println(Arrays.toString(colours.toArray()));
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    list.add("Oracle");
    list.add("SQL");
    list.add("CSS");
    list.add("XML");
    System.out.println("List: " + list);
    // Get the list iterator
    ListIterator<String> iterator = list.listIterator();
    while (iterator.hasNext()) {
        int index = iterator.nextIndex();
        String element = iterator.next();
        System.out.println("Index=" + index + ", Element=" + element);
    }// ww w  .j a  v a2  s .com
    // Reuse the iterator to iterate from the end to the beginning
    while (iterator.hasPrevious()) {
        int index = iterator.previousIndex();
        String element = iterator.previous();
        System.out.println("Index=" + index + ",  Element=" + element);
    }
}

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

    boolean noneStartsWithZ = stringCollection.stream().noneMatch((s) -> s.startsWith("z"));

    System.out.println(noneStartsWithZ); // true
}

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

    boolean anyStartsWithA = stringCollection.stream().anyMatch((s) -> s.startsWith("a"));

    System.out.println(anyStartsWithA); // true
}

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

    boolean allStartsWithA = stringCollection.stream().allMatch((s) -> s.startsWith("a"));

    System.out.println(allStartsWithA); // false
}