Posts

Streams in java

Stream (dictionary meaning) : A stream of things is a large number of them occurring one after another. When i hear about the term stream first thing that comes to mind is 'stream of water' or 'stream of tears ',  which somewhat matches with the above definition. So lets understand with this definition in mind. Suppose we have a water tank(collection) with water filled in it and we need drinkable water from it. To achieve this we will purify the water. Now to purify we need to put a pipe from tank to purifier and purifier will make sure it purifies and filter the drinkable water and discard the not drinkable water. Here in the above example Tank is the synonym of Collection(ArrayList, LinkedList, etc..) and the pipe is a way to transform the collection to stream of water which we feed to purifier as input and the purifier checks every input to check if it is fit drinking else discards it. So purifier is basically a filter over the water stream. Consider this si...
Recent posts