Hello Friends! Welcome back. Modern java libraries have changed a lot since Java 1.8. Collections libraries got impacted and changed a lot since then. We can say that Collections are the biggest beneficiaries of Functional paradigm. In modern Java, collection uses functional programming style a lot and libraries have changed accordingly. In this blog we […]
Category: Java Streams
This blog will give you in depth understanding about a very interesting concept, Collectors. Collectors are very beneficial if you are processing a lot of data in Memory in Java. Collectors have very useful and easy to use reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria and many more. […]
After acquainting the readers with the implementation of various concepts and techniques of functional programming in previous blogs, this blog will make you learn a very interesting concept which is Design Patterns. We will cover various patterns and their implementation in Functional paradigm. First let us discuss what are design patterns. Design pattern can be […]
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 […]