Hacker News new | ask | show | jobs
by chvid 2524 days ago
At least two problems with the java code. Concatenation of strings using the plus operator creates a new string and copies the content of the old, that pushes the complexity of the code from o(n) to o(n2) where n is the number of lines. Secondly order is not guaranteed with the for each operation on streams.

The correct way to do it is using collect(Collectors.joining(“\n”)) or straight forward imperative style (without streams).

I don’t think the general statement holds (that java or buffered reader is cpu bound in particular).

1 comments

Where do you see string concatenation with the plus operator in the posted code?
Haha - nowhere ... I completely misread his code.