简体   繁体   English

使用System.out.printf()的优点和缺点;

[英]Advantages and Disadvantages of using System.out.printf();

I was just wondering what were the advantages and disadvantages of using System.out.printf(); 我只是想知道使用System.out.printf();的优点和缺点是什么System.out.printf(); We normally use System.out.println(); 我们通常使用System.out.println(); or System.out.print(); System.out.print(); but will it make a difference if we use System.out.printf(); 但如果我们使用System.out.printf();它会有所作为System.out.printf(); ? Is there a specific disadvantage or advantage to using System.out.printf(); 使用System.out.printf();是否存在特定的缺点或优势System.out.printf(); or any other print statements? 或任何其他印刷声明?

Thanks. 谢谢。

EDIT: Yes, I do know the difference between printf and println. 编辑:是的,我知道printf和println之间的区别。

Printf allows special formatting: Printf允许特殊格式化:

http://java.sun.com/developer/technicalArticles/Programming/sprintf/ http://java.sun.com/developer/technicalArticles/Programming/sprintf/

That is the advantage. 这是优势。 Otherwise there is no disadvantage to calling print() as you do now. 否则,就像现在一样调用print()没有缺点。

Look at the JavaDoc of the class PrintStream. 查看PrintStream类的JavaDoc There you can see that the print / println methods print a String and printf is 在那里你可以看到print / println方法打印一个String而printf是

  • A convenience method to write a formatted string to this output stream 将格式化字符串写入此输出流的便捷方法
  • using the specified format string and arguments. 使用指定的格式字符串和参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM