java System.out.printf 与 System.out.format

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16234448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:19:23  来源:igfitidea点击:

System.out.printf vs System.out.format

javaformatprintf

提问by Rollerball

Are System.out.printfand System.out.formattotally the same or perhaps they differ in somehow?

System.out.printfSystem.out.format完全一样或者他们以某种方式的不同之处?

回答by NilsH

System.outis a PrintStream, and quoting the javadoc for PrintStream.printf

System.out是 a PrintStream,并引用 javadocPrintStream.printf

An invocation of this method of the form out.printf(l, format, args)behaves in exactly the same way as the invocation out.format(l, format, args)

对表单的此方法的调用与调用的out.printf(l, format, args)行为方式完全相同 out.format(l, format, args)

回答by c.P.u1

The actual implementation of both printfoverloaded forms

两种printf重载形式的实际实现

public PrintStream printf(Locale l, String format, Object ... args) {
    return format(l, format, args);
}

and

public PrintStream printf(String format, Object ... args) {
        return format(format, args);
}

uses the formatmethod's overloaded forms

使用format方法的重载形式

public PrintStream format(Locale l, String format, Object ... args)

and

public PrintStream format(String format, Object ... args)

respectively.

分别。

回答by Suresh Atta

No difference.They both behave the same.

没有区别。他们都表现得一样