Example usage for java.util List forEach

List of usage examples for java.util List forEach

Introduction

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

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<Integer> l = Arrays.asList(1, 3, 2, 4, 7, 8, 9, 6, 5);
    l.forEach(i -> { //Consumer is not even imported
        System.out.println(i + 10);
    });/*w w  w. j a v  a  2 s.c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> l = Arrays.asList(1, 3, 2, 4, 7, 8, 9, 6, 5);
    l.forEach(Main::methodWithSameInput);
}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    numbers.forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> l = Arrays.asList(1, 3, 2, 4);
    l.forEach(getConsumer(10));
}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    numbers.forEach(new Consumer<Integer>() {
        @Override/*from   w w w.j  a v a2 s. co  m*/
        public void accept(Integer integer) {
            System.out.println(integer);
        }
    });

}

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

    names.forEach(System.out::println);
}

From source file:httpasync.AsyncClientPipelined.java

public static void main(final String[] args) throws Exception {
    CloseableHttpPipeliningClient httpclient = HttpAsyncClients.createPipelining();
    try {/*  w  w w.  j av a 2  s  . c om*/
        httpclient.start();

        HttpHost targetHost = new HttpHost("money.moneydj.com", 80);
        HttpGet[] resquests = { new HttpGet("/us/basic/basic0001/Person"),
                new HttpGet("/us/basic/basic0001/AA"), new HttpGet("/us/basic/basic0001/PSG"),
                //                    new HttpGet("/docs/introduction.html"),
                //                    new HttpGet("/docs/setup.html"),
                //                    new HttpGet("/docs/config/index.html")
        };

        Future<List<HttpResponse>> future = httpclient.execute(targetHost,
                Arrays.<HttpRequest>asList(resquests), null);
        List<HttpResponse> responses = future.get();
        responses.forEach(System.out::println);

        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:Main.java

public static void main(String[] argv) {
    List<Person> persons = Arrays.asList(new Person("Joe"), new Person("Jim"), new Person("John"));
    persons.forEach(p -> p.setLastName("Doe"));

    persons.forEach(p -> System.out.println(p));
}

From source file:Main.java

public static void main(String[] args) {
    List<Trade> trades = TradeUtil.createTrades();

    trades.forEach(trade -> System.out.println(trade));

    trades.forEach(System.out::println);

    Consumer<Trade> printTrade = trade -> System.out.println(trade);
    trades.forEach(printTrade);//  w w w.  j a v a2  s. c o m
}

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