-
Lambdas can references static and instance variables from wihtin. They can also access local variables which are effectively final - meaning the variable has not been reassigned or is literally labeled final!
-
I must know the following functional interfaces!:
Supplier<T>:get()returns TConsumer<T>: `accept(T t) returns voidBiConsumer<T, U>: `accept(T t, U u) returns voidPredicate<T>:test(T t)returns boooleanBiPredicate<T, U>:test(T t, U u)returns booleanFunction<T, R>:apply(T t)returns RBiFunction<T, U, R>:apply(T t, U u)returns RUnaryOperator<T>:apply(T t)returns TBinaryOperator<T>:apply(T t1, T t2)returns T
-
An
Optionalcan be used to store a value or its empty. We can can useifPresent()andget()to get its value. -
We have 3 methods for Optionals which accept functional interfaces:
ifPresent(Consumer c)elseGet(Supplier s)orElseThrow(Supplier c)
- Stream pipelines have 3 parts:
-
Source of data
-
Intermediate Operations - optional and can be multiple. E.g.
filter(),flatMap(),sorted() -
Terminal Operation - e.g.
allMatch(),count(),forEach()
-
We can create streams for primitive data types, for these we must use
DoubleStream,IntStreamandLongStream! -
We can quickly generate a stream of INTEGERS within a range using
range(i,j)andrangeClosed(i,j). These methods are only available on DoubleStream and IntStream! -
We have access to
average(),min(),max()for these primitive streams. We can also generate aSummaryStatisticby callingsummaryStatistics() -
We have functional interfaces specifically for boolean, e.g.
BooleanSuppliercan be use to generate a primitive boolean value!