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.
Syntax: There is two types of string format() method
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static String format(Locale loc, String form, Object... args)
public static String format(String form, Object... args)
- The locale value to be applied on the format() method
- The format of the output string.
- args specifying the number of arguments for the format string. It may be zero or more.
Return Type: Formatted string.
- NullPointerException: If the format is null.
- IllegalFormatException: If the format specified is illegal or there are insufficient arguments.
My Company name is GeeksforGeeks My answer is 47.65734000 My answer is 47.65734000
My Company name is: GFG, GFG and GeeksforGeeks