Java Formatter.out()
Syntax
Formatter.out() has the following syntax.
public Appendable out()
Example
In the following code shows how to use Formatter.out() method.
/*w w w.j a va 2s .c om*/
import java.util.Formatter;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
Formatter formatter = new Formatter(buffer, Locale.US);
// format a new string
String name = "from java2s.com";
formatter.format("Hello %s !", name);
// print the formatted string with default locale
System.out.println(formatter);
// print the output
System.out.println(formatter.out());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »