Last active
August 23, 2019 13:01
-
-
Save hakaneroztekin/6aa7b6870cce7315c9c467d689d0b321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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