0

Below is code of printf() and format() methods present in java.io.PrintStream

  public java.io.PrintStream printf(java.lang.String, java.lang.Object...);
  public java.io.PrintStream printf(java.util.Locale, java.lang.String, java.lang.Object...);
  public java.io.PrintStream format(java.lang.String, java.lang.Object...);
  public java.io.PrintStream format(java.util.Locale, java.lang.String, java.lang.Object...);

These methods consist of two format parameters. But, when we pass a single argument to these methods and run the program, it ran successfully.

My question is where these methods are defined with single parameters similar to print() or println() methods as these methods consist of single parameter(defined in java.io.PrintStream).

I tried to execute following code and it is running fine.

public class FormatAndPrintf {
public static void main(String args[]){
    System.out.printf("This is printed using printf() function.");
    System.out.format("This is printed using format() function.");
    System.out.println("++++++++++++++++++++++++++++++++++++++++==");
}
}
Dani
  • 1,825
  • 2
  • 15
  • 29
S Kumar
  • 555
  • 7
  • 21

1 Answers1

1

The ... operator is a way to pass a (variable-sized) array of arguments to a method without having to manually create the array. Passing none, as you are doing in the enclosed snippet, means that the method will get an empty array.

Mureinik
  • 297,002
  • 52
  • 306
  • 350