Writing 1000 values is not a lot, so both solutions will get the job done. If you use the defaults of PrintWriter (no automatic line flushing), it should be similar in performance compared to writing to a StringBuilder first. Disk IO should be the bottleneck in both cases.
Once you have to deal with huge outputs, performance might become relevant, but both approaches are not optimal in that case. In that case, the nio package might be worth a look if IO performance is critical.
But from what you describe, I would not recommend nio
, as its API is complicated. Start with a simple StringBuilder
if it is convenient or use PrintWriter
directly. Both should be sufficient for your use case.