[Java] What is flatMap?

In the official documentation

Stream flatMap(Function<? super T,? extends Stream<? extends R>> mapper)

Returns a stream consisting of the contents of each element of this stream replaced with the contents of a mapped stream (obtained by applying the specified mapping function to each element).

Stream (Java Platform SE 8 )

in short

It is processed by the following procedure

  1. Receive objects in Stream and convert them to Stream
  2. Combine each converted Stream into one Stream

Example

abcdeIs output


Arrays.asList("a,b,c", "d,e")
    .flatMap(str -> Arrays.stream(str.split(','))
    .forEach(str -> System.out.print(str));

Recommended Posts

[Java] What is flatMap?
What is Java <>?
What is Java
What is Java Encapsulation?
What is Java technology?
What is Java API-java
[Java] What is JavaBeans?
[Java] What is ArrayList?
What is Java Assertion? Summary.
What is a Java collection?
[Java] What is jaee j2ee?
[Java] What is class inheritance?
[Java basics] What is Class?
What is java escape analysis?
What is JVM (Java Virtual Machine)?
[Java] What is Concurrent Modification Exception?
What is a lambda expression (Java)
What is Cubby
What is Docker?
What is null? ]
What is Keycloak
What is maven?
What is Jackson?
What is Docker
What is self
What is Jenkins
What is ArgumentMatcher?
What is params
What is SLF4J?
What is Facade? ??
What is Gradle?
What is POJO
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is a class in Java language (3 /?)
What is the best file reading (Java)
What is a class in Java language (1 /?)
What is Java and Development Environment (MAC)
What is a class in Java language (2 /?)
What is the main method in Java?
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is the Java Servlet / JSP MVC model?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?