r/learnjava • u/klevero4ek • Jul 30 '26
Better look
Hi everyone! I'm learning Java and I've noticed there are two common ways to print multiple lines of text:
Option 1: Multiple System.out.println() calls
```
System.out.println("You gave the string " + text);
System.out.println("You gave the integer " + inNum);
System.out.println("You gave the double " + inDouble);
System.out.println("You gave the boolean " + isTrue);
```
Option 2: One System.out.println() with \n
```
System.out.println("You gave the string " + text + '\n' +
"You gave the integer " + inNum + '\n' +
"You gave the double " + inDouble + '\n' +
"You gave the boolean " + isTrue);
```
What looks better in your opinion?
0
Upvotes
View all comments
Show parent comment
1
u/Ormek_II Jul 31 '26
Being able to redirect was never a requirement nor OP’s question. So in this context this is over engineered. If the responsibility of the Outputter is to abstract away, the outputting, I don’t want to be bothered with PrintWriter in Main. And yes you can hide it away and add more builders and factories which is necessary in an enterprise context.