Java Data Type Tutorial - Java String.format(String format, Object ... args)








Syntax

String.format(String format, Object ... args) has the following syntax.

public static String format(String format,  Object ... args)

Example

In the following code shows how to use String.format(String format, Object ... args) method.

import java.util.Locale;
// w w  w  .  ja va  2 s .  co m
public class Main {

  public static void main(String[] args) {
  
    double piVal = Math.PI;
       
    System.out.format("%f\n", piVal);
      
  }
}

The code above generates the following result.