Difference between printf and format

10

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)
    
asked by anonymous 19.04.2017 / 22:51

1 answer

9

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 invocation out.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

    
20.04.2017 / 17:18