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

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

    The second option is almost certainly faster because each call to println() causes a system function to be called. This jump to kernel code takes some amount of time. This is the reasoning behind buffering in in C.

提交回复
热议问题