Java Optimizations

前端 未结 5 1825
忘了有多久
忘了有多久 2021-01-24 04:38

I am wondering if there is any performance differences between

  1. String s = someObject.toString(); System.out.println(s);

    and

  2. System.out.pr

5条回答
  •  误落风尘
    2021-01-24 05:10

    If you have critical code sections that demand performance, avoid using System.out.println(). There is more overhead incurred by going to standard output than there ever will be with a variable assignment.

    Do solution 1.

    Edit: or solution 2

提交回复
热议问题