A few weeks ago, I was looking for a way to extract a specific value from a file and came across this question that introduced me to the Stream Object.
My first instinct was to find out whether this object would help other file operations, for example, to replace several placeholders with the corresponding values, for which I used BufferedReader and FileWriter . I barely managed to create any working code, but since then I began to be interested in articles that covered the topic, so I could understand the intended use of Stream .
Along the way, I came across Optional and understood it well and now I can identify cases where it is convenient for me to use Optional , keeping my code clean and clear. However, I canβt say that this is the case for Stream , not to mention the fact that it may not have provided a performance gain, I thought it would bring and still need a finally clause in cases where IO is involved .
Here is the main problem that I was trying to wrap my head with in mind that I have mainly worked on single-threaded programming so far: when is it preferable to use Stream in addition to parallel processing?
Is it necessary to make the operation massive in a certain subset of a large data set, where Collection would be used when trying to access specific objects of the specified collection? Although this seems to be intended for use, I'm still not sure if the example I linked at the beginning of my question is your typical use case.
Or is it just a construct used to make code smaller thanks to a lambda expression with a victim of readability? (Nothing against lambda if it is used correctly, but I saw most of the Stream usage example where it is completely inaudible, which did not help me in a general understanding)
source share