Java Stream How to - Convert integer to String with map








Question

We would like to know how to convert integer to String with map.

Answer

//from ww w .  j ava 2s.  co  m
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    Arrays.asList(1,20,40,4)
    .stream()
    .filter(n -> n<30)
    .map(n -> "number: " + String.valueOf(n))
    .forEach(n -> System.out.println(n));
  }
}

The code above generates the following result.