DEV Community

Discussion on: Navigating the uncharted Stream

Collapse
 
lluismf profile image
Lluís Josep Martínez

If you want to get rid of the loop (whatever the reason) I guess you need to change the input values. Instead of 2 lists, use a single collection of KeyValue objects or a Map. And you would be able to use map and a closure to perform the replacement.

Regarding efficiency, if the input file is small no problem. But if it's in the order of gigabytes, converting the Stream to String needs to allocate a huge array of bytes in the heap and you risk an out of memory. Writing to the output file as a stream OTOH will be efficient - in memory terms (not CPU).