Syntax of String format()
There are two types of string format() methods mentioned below:
public static String format(Locale loc, String form, Object... args) public static String format(String form, Object... args)
Parameters
locale: the locale value to be applied on the format() method format: The format of the output string. args: args specifying the number of arguments for the format string. It may be zero or more.
Return Value
- Formatted string.
Exception Thrown
- NullPointerException: If the format is null.
- IllegalFormatException: If the format specified is illegal or there are insufficient arguments.
Java String format() Method With Examples
In Java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string.
Contact Us