Why have you marked all the methods static in the second version?
Why do your methods in the first version return
this rather than an
int[] or similar? If you are reading into a field of the current object, why not make the method
void? There may be a good reason for returning
this: you can write
myObject.foo(...).bar(...).baz(...).biz(...).buzz(...);
If you go through the API for
StringBuilder you will see that is how must of its methods are designed.
I suggest you indent your Streams code differently:-
You can replace the sort() call with this:-
It is probably better to sort the IntStream in line 3 than the Stream<
String> in line 2, otherwise "19" will come before "2".
For consecutive numbers, consider starting with the
IntStream#range() and
IntStream#rangeClosed() methods.