In this part of the tutorial, we will Introduce Lambda and Functional Interfaces. These two things should always be discussed together as lambda can’t exist without Functional Interfaces. Lambda is the most discussed topic in Java after Java 8 launch. Lambda is basically a building block of Functional ProgrammingLambda is a function without a Name […]
Author: admin
Before going into the details of functional programming, the first concept which needs to be discussed is why functional programming ? Traditionally, JAVA was used solely for object oriented programming which included dealing with creation and relation between objects, inheritance, polymorphism etc. But now-a-days functional programming gives us one more tool to work with. The […]
What are the functional data structures? A functional data structure is something that is not imperative and yes, implemented in a functional way. what do I mean by that is, Functional data structures do not use any imperative features like there will be no updates and modifications, and no such operations on a data structure […]
The most important property of Streams is Laziness. Streams are lazy, as the Intermediate Operations in Stream pipeline, not get evaluated until the terminal operation is invoked. Or we can say all intermediate operations on streams are lazy. In what sense? Consider the following example. Explanation: While creating the stream of filtered elements, we are […]
To provide support to work with primitives int, long and double, Java provides three primitive specialized implementations of Stream. IntStream LongStream DoubleStream This is how we can create primitive streams using these interfaces. Creating Primitive Stream: Using of() method | Arrays.stream() method We use of() method with primitive streams to get the stream of corresponding […]
With finite or Bounded streams we supply elements up to ceratin stream length. Whereas, in infinite streams, we don’t have any stream length. Ways of creating infinite streams: Stream<T> iterate(T seed, UnaryOperator<T> f): iterate() method of Stream returns an infinite sequential ordered stream. It takes a seed and UnaryOperator. Seed is the first element of […]
Ways of creating finite streams: collection.stream() call on a Collection to get a stream of all the elements contained in that collection. This gives a Stream of elements contained in the list. We can use this stream() method with every collection, but there is no direct way to create a stream from a map because […]
Parallelism is dividing a problem into sub-problems and executing them on multiple resources. For example, Computers having a Multi-Core processor are faster. Similarly, our programs can be designed in a way so that they can take advantage of multi-core processing. Streams API allows us to do that. We can create Parallel Streams to take advantage […]
The Stream flatMap() is used to flatten the stream of streams to stream of individual elements. What is Flattening? Flattening is like converting Collection of collection to a single collection of all those elements present in all collections. Consider two streams, that we want to merge into one. But we can not merge their elements […]
Functional programming languages typically provide several useful higher-order functions. (a function that takes one or more functions or returns a function or does both is a higher-order function). The most common Higher-order functions are Filter, Map and Reduce. filter method As the name suggests, the filter method filters the elements based upon the condition we […]