10
Is there any difference between using the printf
and the 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)
10
Is there any difference between using the printf
and the 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)
9
In accordance with the documentation:
A 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, because the out.printf
is just a different way of invoking the out.format
.
Searching the source code of the open source version of java (Openjdk), what happens is that the printf
makes a call to the format
and nothing else:
public PrintStream printf(String format, Object ...args) {
return format(format, args);
}
source: grepcode.com
Browser other questions tagged java string
You are not signed in. Login or sign up in order to post.