Primitive Data Types & Wrapper Classes: Interface
Primitive Data Types & Wrapper Classes: Interface
float decimal number (1.4e-45 to 3.4e+38) 0.0 32 bits float f = 1.3f; Float
double decimal number (4.94e-324 to 1.797e+308) 0.0 64 bits double d = 0.5; Double
Can not create instance of an Abstract class Can not create an instance of an Interface
Method References
Create new object -> new Cat() () -> new Cat() Cat::new
Functional Composition /
Name Input Type Return Type Method Bi Type
Lambda Chaining
and(Predicate);
Predicate<T> T boolean test or(Predicate) BiPredicate<T, R>
negate()
andThen(Function)
Function<T,R> T R apply BiFunction<T,U, R>
compose(Function)
filter
map
limit
Returns new streams skip
Intermediate
Lazy distinct
sorted
flatMap
peek
forEach
collect
count
Stream is consumed min
Terminal
Can not be reused max
findAny
anyMatch
noneMatch
Intermediate Operations
filter(i -> i % 2 == 0)
filter Used for filtering data Predicate<T>
filter(o -> Objects.nonNul(o))
Intermediate Operations
map(i -> i * i)
Transforms the received data
map Function<T, R> map(s -> s.toUpperCase())
from one form to another
map(b -> DriverFactory.get(b))
sorted(Comparator.naturalOrder())
sorted Sorts the data (asc / desc) Comparator
sorted(Comparator.reverseOrder())
forEach Used for consuming the given object Consumer<T> forEach(e -> e.click())
collect To collect the object into a list, set, map etc Multiple implementations collect(Collectors.toList())
min(Comparator.naturalOrder())
min first element after comparing all Comparator
min(Comparator.reverseOrder())
max(Comparator.naturalOrder())
max last element after comparing all Comparator
max(Comparator.reverseOrder())
findFirst() Give the first one from the stream N/A findFirst()
Collect Usage
To a list .collect(Collectors.toList())
To a set
.collect(Collectors.toSet())
(no duplicates)
.collect(Collectors.joining())
Join all
.collect(Collectors.joining(","))
To a map .collect(Collectors.groupingBy(...))
Stream Source
Source Usage
map.entrySet().stream()
Map map map.keySet().stream()
map.values().stream()
String a = "udemy"
String b = "hi" Stream.of(a, b, c.....)
String c = "hello"
Comparator
Comparator Usage
min(Comparator.naturalOrder())
Comparator.naturalOrder() max(Comparator.naturalOrder())
sorted(Comparator.naturalOrder())
min(Comparator.reverseOrder())
Comparator.reverseOrder() max(Comparator.reverseOrder())
sorted(Comparator.reverseOrder())
//Student name
Comparator.comparing(Function)
min(Comparator.comparing(s -> s.getName()))
Primitive Streams
mapToInt(Function) ==>
sum()
Stream<Integer> IntStream
average()
<== boxed()
mapToLong(Function) ==>
sum()
Stream<Long> LongStream
average()
<== boxed()
mapToDouble(Function) ==>
sum()
Stream<Double> DoubleStream
average()
<== boxed()