Java 8 stream map

Let's map a list of words using Java 8 streams:

List<String> words = Arrays.asList("A", "bbb", "CC", "dd");
 
// Map the words to UPPERCASE and join them with the ":" separator
String joined = words.stream()
        .map(String::toUpperCase)
        .collect(Collectors.joining(":")); // "A:BBB:CC:DD"
Example of mapping Java 8 streams using the stream.map() method.

Calling the map method of a stream returns another stream with the mapped values. In this example the words are mapped into their uppercase versions, and the resulting stream is converted to a string by collecting all of its items and concatenating/joining them with a joining collector, using the ":" separator.

Subscribe to Java 8 Resources

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe