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

后端 未结 8 938
一生所求
一生所求 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 10:58

    For platform dependent line separator I would use:

    String ls = System.getProperty("line.separator");
    System.out.print(ls+ls+ls+ls+ls);
    

    That should work on win, linux or mac.

提交回复
热议问题