Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created November 2, 2014 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfarcic/fa206aa5d611820ca174 to your computer and use it in GitHub Desktop.
Save vfarcic/fa206aa5d611820ca174 to your computer and use it in GitHub Desktop.
package com.technologyconversations.java8exercises.streams;
import java.util.ArrayList;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class ToUpperCase {
public static List<String> transform7(List<String> collection) {
List<String> coll = new ArrayList<>();
for (String element : collection) {
coll.add(element.toUpperCase());
}
return coll;
}
public static List<String> transform(List<String> collection) {
return collection.stream() // Convert collection to Stream
.map(String::toUpperCase) // Convert each element to upper case
.collect(toList()); // Collect results to a new list
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment