Lambda Built in Func Int Flashcards
Give a brief description of the functional interface Predicate{T}
Check a condition and returns a boolean value as result
Ex. filter() method in java.util.stream.Stream which is used to remove elements in the stream that dont match the given condition(predicate) as argument
boolean test(T t)
Give a brief description of the functional interface Consumer{T}
Operation that takes an argumenet but returns nothing
ex. forEach() method in collection and in java.util.stream.Stream; this method is used for transversing all the elements in the collection or stream
void accept(T t)
Give a brief description of the functional interface Function{T, R}
functions that take an argument and return a result
ex. In map() method, to transform or operate on the passed value and return a result
R apply(T t)
Give a brief description of the functional interface Supplier{T}
Operation that returns a value to the caller( the returned value could be same or different values)
generate() method in java.util.stream.Stream to create an infinite stream of elements
T get()
What is the difference between andThen() and compose() methods in Function interface?
The andThen() method applies the passed argumenet after calling the current Function. The compose() method calls the argument before calling the current function
What is constructor reference?
Using ::new
can be used with supplier
Supplier{String} newString = String::new;
System.out.println(newString.get());
or with function
Function{String, Integer} anotherInteger = Integer::new;
System.out.println(anotherInteger.apply(“100”));
Which of the following are valid lambda expressions?
- () -> “”
- x,y -> x+y
- (Coyote y) -> return 0
- (Camel c) -> { return}
- Wolf w -> 39
- () ->
- (Animal z, m) -> a
1 and 4 are valid
What does IntFunction receives as an argument?
takes a primitive argument but can return anything