Java 与System.out.printf相比,System.out.println执行得更快吗

Java 与System.out.printf相比,System.out.println执行得更快吗,java,hashmap,conditional-statements,printf,execution-time,Java,Hashmap,Conditional Statements,Printf,Execution Time,所以,我遇到了一个问题,我被要求创建一个字典来存储一个数字作为键,值作为一个电话号码。我的第一个代码无法及时执行问题,而我的第二个迭代却做到了。为什么会这样? 我的第一个代码片段:- while(sn.hasNext()){ String s=sn.nextLine(); System.out.printf((pb.get(s)==null)?"Not found":"%d=%s%n",s,pb.get(s));} //pb is the

所以,我遇到了一个问题,我被要求创建一个字典来存储一个数字作为键,值作为一个电话号码。我的第一个代码无法及时执行问题,而我的第二个迭代却做到了。为什么会这样? 我的第一个代码片段:-

while(sn.hasNext()){
    String s=sn.nextLine();
    System.out.printf((pb.get(s)==null)?"Not found":"%d=%s%n",s,pb.get(s));} //pb is the hashmap obj
我的第二个代码:

while(sn.hasNext()){
    String s=sn.nextLine();
    if(pb.get(s)==null){
         System.out.println("Not found");
    else System.out.println(s+"="+pb.get(s));}

如果我删除System.out.printf中的条件语句并用If-else替换它,那么它将在一段时间内通过所有测试用例。为什么会这样?

print语句本身的执行时间很短,不会产生任何影响。这实际上是hackerrank的一个问题,所以在使用第一个语句时,我无法通过5个用例中的2个,但一旦我实现了第二个,它就可以工作了。为了交叉检查,我删除了printf并使用了println?操作员和它仍然工作正常。是什么使printf语句在执行时间方面有所不同?