Java Formatter.close()
Syntax
Formatter.close() has the following syntax.
public void close()
Example
In the following code shows how to use Formatter.close() method.
/* ww w.j a va2 s . co m*/
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
System.out.println(formatter);
// close the formatter
formatter.close();
// attempt to access the formatter results in exception
System.out.println(formatter);
}
}
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »