Getting stream of char from string.chars()

Transcribed from the original LinkedIn image post.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
/**
 * Getting a stream of characters from String.chars()
 */
public class Day05 {
    public static void main(String[] args) {
        String fileNameWithExtension = "a-very-large-file-name.docx";

        // this will give an IntStream where the int's are character code
        // Getting characters by mapping to char
        fileNameWithExtension.chars()
            .mapToObj(ch -> (char) ch)
            .forEach(System.out::println);
    }
}

The original LinkedIn graphic is preserved below.

Day 5 LinkedIn post