Skip to content

Instantly share code, notes, and snippets.

@nkalra0123
Created January 19, 2020 06:26
Show Gist options
  • Save nkalra0123/5134e76688151045a58190d43124b145 to your computer and use it in GitHub Desktop.
Save nkalra0123/5134e76688151045a58190d43124b145 to your computer and use it in GitHub Desktop.
Function, Consumer Functional Interfaces
// Function, Consumer
Stream.of(strings).filter(s -> s.matches("\\d+")).map(new Function<String, Integer>() {
/**
* Applies this function to the given argument.
*
* @param s the function argument
* @return the function result
*/
@Override
public Integer apply(String s) {
return Integer.parseInt(s);
}
}).forEach(new Consumer<Integer>() {
/**
* Performs this operation on the given argument.
*
* @param o the input argument
*/
@Override
public void accept(Integer o) {
System.out.println(o);
}
});
Stream.of(strings).filter(s -> s.matches("\\d+")).map(s -> Integer.parseInt(s)).forEach(s-> System.out.println(s));
Stream.of(strings).filter(s -> s.matches("\\d+")).map(Integer::parseInt).forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment