Java Stream flat map String Stream to char Stream

Introduction

Convert a stream of strings to a stream of characters.

import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Stream.of("XML", "Java",  "CSS","Javascript","C++","C")
        .map(name  ->  name.chars())/*w  w w  . ja va2s .c  om*/
        .flatMap(s ->  s.mapToObj(n ->  (char)n))
        .forEach(System.out::println); 

  }
}



PreviousNext

Related