Stream flatMapToInt(Function mapper) example

Description

Stream flatMapToInt(Function<? super T,? extends IntStream> mapper) returns an IntStream by replacing this stream with a mapped stream produced by applying the provided mapping function.

Syntax

flatMapToInt has the following syntax.


IntStream flatMapToInt(Function<? super T,? extends IntStream> mapper)

Example

The following example shows how to use flatMapToInt.


import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
//ww w  .ja va 2s. c  om
public class Main {
  public static void main(String[] args) {
    List<String> stringList = Arrays.asList("1.2","2.2","3","4","5");

    stringList.stream()
           .flatMapToInt(n-> IntStream.of(Integer.parseInt(n)) )
           .forEach(System.out::println);
  }
}




















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder