Victor Lyuboslavsky Victor Lyuboslavsky - 2 months ago 10
Java Question

How to use Java's lambda expressions to print an array?

How can I achieve the following array print using Java 8's lambda expressions?

int[] values = new int[16];
// Populate values

for (int value : values) {
System.out.println(Integer.toUnsignedString(value, 16));
}

Answer
Arrays.stream(values)
      .mapToObj(i -> Integer.toUnsignedString(i, 16))
      .forEach(System.out::println);