System.out.println() vs \n in Java

后端 未结 8 910
一生所求
一生所求 2020-12-28 10:08

Let\'s say I wanted to print 5 lines. Which is the best method (for performance and readability).

System.out.println();
System.out.println();
System.out.prin         


        
8条回答
  •  [愿得一人]
    2020-12-28 11:07

    As you can see from the answers, this is a matter of preference. The example you give is a very simple one where the performance gains and readability issues are minimal. In some more complicated cases, however, the choice of which seemingly equivalent methods to use could be crippling to your code, or could make it indecipherable to a neighbor.

    If code looks like it's getting kind of messy, try abstracting out the messy code and giving it an easy to read method name.

    So yes, this is a matter of preference.

    (Edit: no, this is apparently not a matter of preference (^o^ )// )

提交回复
热议问题