Many times you need to create a list of objects of your custom Class.
Suppose you will be having the values to instantiate the objects of your class with those values.
So you can go ahead in traditonal way & can create a objects & add all those to a list.
Seems straight & simple, now one catch is that the creation of the object of your class takes time.
So if you go in traditional serial way then it will take enough time. Now your sharp mind quickly thinks about threading.
But again having multithreading, you need to add sufficient code to handle this requirement & if in future you want to go serial then you will to make sufficient necessary carful changes to remove multithreading.
What do you think now?
Hmmm, lets use the concept of Functional programming in Java now. Means we can mix & match these features in our code to get the efficient solution. So for this requirement above we will take functional approach like shown below -
Suppose you will be having the values to instantiate the objects of your class with those values.
So you can go ahead in traditonal way & can create a objects & add all those to a list.
Seems straight & simple, now one catch is that the creation of the object of your class takes time.
So if you go in traditional serial way then it will take enough time. Now your sharp mind quickly thinks about threading.
But again having multithreading, you need to add sufficient code to handle this requirement & if in future you want to go serial then you will to make sufficient necessary carful changes to remove multithreading.
What do you think now?
Hmmm, lets use the concept of Functional programming in Java now. Means we can mix & match these features in our code to get the efficient solution. So for this requirement above we will take functional approach like shown below -
Check commenting parallel() & you will see how easy it is to switch between parrallel processing & serial processing. Even if there is any change in the order of data for each apple, then you just need to make the relevant change in createApple().