Lambda expressions (Java)

Mogaka Polycarp
Sep 22, 2022

--

High order functions:Stream,Map,collect and Filter

Map simply transforms one object into another by applying a function

It takes a function as an argument

Filter is basically used to return objects that meet a certain condition in a stream

It takes a predicate as a parameter,a predicate(a function that takes one argument and returns a boolean

A stream takes inputs from the collection i.e Arrays,Maps,Lists

Collect returns the result of the lambda function in a unified manner

Example A function to return even numbers

List<String> num = Arrays.asList(“1”,”2",”3",”4",”5",”6",”7",”8");

return num.stream().maps(s->Integer.valueOf(s))
.filter(number->number%2==0)
.collect(Collectors.toList());

--

--

Mogaka Polycarp
Mogaka Polycarp

Written by Mogaka Polycarp

Software Engineer, creative thinker passionate about creating Applications and data solutions

No responses yet