PrintWriter.format(String format, Object ... args) has the following syntax.
public PrintWriter format(String format, Object ... args)
In the following code shows how to use PrintWriter.format(String format, Object ... args) method.
import java.io.*; //from www .j av a 2s.com public class Main { public static void main(String[] args) { String s = "tutorial from java2s.com"; try { PrintWriter pw = new PrintWriter(System.out); // format text with default locale // %s indicates a string will be placed there, which is s pw.format("This is a %s program", s); // flush the writer pw.flush(); } catch (Exception ex) { ex.printStackTrace(); } } }
The code above generates the following result.