Functional Programming in Java
Functional Programming in Java
Functional Programming in Java
Procedural programming
Object Oriented programming
Parallel Processing Approach
int sum = 0;
sum += i;
System.out.println(sum);
import java.util.Arrays;
.filter(a -> a % 2 == 0)
.toArray();
System.out.println(Arrays.toString(evenArray));
In this example, the input array is converted to stream. The filter() method is invoked for
each value in the stream and it is evaluated with the expression a -> a % 2 == 0.
The filter() method passes the value to the next operation i.e. toArray() only if the expression
inside it evaluates to true. So, in this case, only 2 and 4 are passed to toArray() operation, and
hence the output is [2, 4].
Here, we didn't define the steps to filter the even numbers. Instead, we told the compiler what
we want via the expression filter(a -> a % 2 == 0).
f(x)=3x.
In functional programming, the software is developed around the evaluation of
functions.
The functions are isolated and independent, and they depend only on the
arguments passed to them and do not alter the program's state like modifying a
global variable.