Skip to content

Instantly share code, notes, and snippets.

@hakaneroztekin
Last active August 23, 2019 13:01
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 hakaneroztekin/6aa7b6870cce7315c9c467d689d0b321 to your computer and use it in GitHub Desktop.
Save hakaneroztekin/6aa7b6870cce7315c9c467d689d0b321 to your computer and use it in GitHub Desktop.
public class StreamIntermediateOperations {
// map: The map method is used to map the items
// in the collection to other objects according to the Function passed as argument.
List number = Arrays.asList(2,3,4,5);
List square = number.stream().map(x->x*x).collect(Collectors.toList());
// filter: The filter method is used
// to select elements as per the Predicate passed as argument.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().filter(s->s.startsWith("S")).collect(Collectors.toList());
// sorted: The sorted method is used to sort the stream.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().sorted().collect(Collectors.toList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment