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
System.out.printf vs System.out.format
提问by Rollerball
Are System.out.printfand System.out.formattotally the same or perhaps they differ in somehow?
是System.out.printf和System.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 invocationout.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.
分别。

