Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Created May 3, 2020 01:18
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 diegopacheco/8d5c3ea0e2e82acdcc5d3fb3ab2d7e23 to your computer and use it in GitHub Desktop.
Save diegopacheco/8d5c3ea0e2e82acdcc5d3fb3ab2d7e23 to your computer and use it in GitHub Desktop.
Java Simple Stream
List<String> rawValues = Arrays.asList(new String[] { "Peter","Adam", "Allan","Anna","John","Paul","Peter" });
List<String> people = rawValues
.stream()
.distinct()
.sorted()
.filter( name -> name.startsWith("A"))
.map(String::toUpperCase)
.limit(2)
.collect(Collectors.toList());
System.out.println("first 2 People who started with A: " + people);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment