In this example, we create the IntConsumer interface and iterate over them with forEach().
Java 8 IntConsumer Example
import java.util.Arrays;
import java.util.function.IntConsumer;
public class JavaForEachConsSpec {
public static void main(String[] args) {
int[] inums = { 3, 5, 6, 7, 5 };
IntConsumer icons = i -> System.out.print(i + " ");
Arrays.stream(inums).forEach(icons);
}
}
Output:
3 5 6 7 5
Comments
Post a Comment