Functional Interfaces: Consumer

Performs an operation on an object.

Overview

Examples

List.of(1, 1, 2, 3, 5, 8, 13)
    .forEach(System.out::println); // Print each value.
Stream.of(1, 1, 2, 3, 5, 8, 13)
    .forEach(System.out::println); // Print each value.

Output

Both of above examples produce this output:

1
1
2
3
5
8
13