Formatter format(String, Object...): This method is available in java.util.Formatter class of Java.
Syntax:
Formatter java.util.Formatter.format(String format, Object... args)
This method writes a formatted string to this object's destination using the specified format string and arguments.
Parameters:
format: A format string as described in Format string syntax.
args: Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored.
Returns: This formatted
Throws:
1. IllegalFormatException - If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions.
2. FormatterClosedException - If this formatter has been closed by invoking its close() method
Approach
Java
import java.util.Formatter;import java.util.Locale;public class Formatterformat {public static void main(String[] args) {StringBuffer buffer = new StringBuffer();Formatter formatter = new Formatter(buffer, Locale.UK);formatter.format("Hello %s ", "Java");System.out.println(formatter);}}
Output:
Hello Java
No comments:
Post a Comment