I have a stream of Stream.of("foo", "egg") lines Stream.of("foo", "egg") , I want to break each line into a stream of characters and work further with each character separately.

For example, print a character and after it an exclamation mark

 f!o!o!e!g!g! 

I thought it could be done like that.

 Stream.of("foo", "egg").flatMap(s -> s.chars()).forEach(c-> System.out.print(c+"!")); 

But the compiler swears at such a decision.

  • one
    Use flatMapToInt - Roman Danilov
  • Thank you, helped by Stream.of("foo", "egg").flatMapToInt(CharSequence::chars).forEach(c-> System.out.print((char) c+"!")); - LuckyMiv

0