Is there any difference between using printf
and format
?
Example 01:
float nota = 5.3f
System.out.printf ("Sua nota: %.2f", nota)
Example 02:
float nota = 5.3f
System.out.format ("Sua nota: %.2f", nota)
Is there any difference between using printf
and format
?
Example 01:
float nota = 5.3f
System.out.printf ("Sua nota: %.2f", nota)
Example 02:
float nota = 5.3f
System.out.format ("Sua nota: %.2f", nota)
According to documentation :
The convenience method to write a formatted string to this output stream using the specified format string and arguments. An invocation of this method of the form
out.printf(format, args)
behaves in exactly the same way as the invocationout.format(format, args)
That is, there is no difference, since out.printf
is just a different way of invoking out.format
.
The source code of the open source version of java (OpenJDK), what happens is that printf
makes a call to format
and nothing else:
public PrintStream printf(String format, Object ...args) {
return format(format, args);
}
source: grepcode.com