MessageFormat format() method in Java with Example : Set – 2
The format() method of java.text.MessageFormat class is used to get the formatted array of object according to the specified pattern of message format object. new string pattern will be considered while performing the action.
public static String format(String pattern, Object... arguments)
Parameter: This method takes following argument as a parameter.
- pattern :– string pattern according to which array of object will be formatted
- arguments :- array of object over which formatting is going to take place.
Return Value: This method returns string value which will have the formatted array of object in string formate.
Exception: This method throws NullPointerException if pattern is null.
Below are the examples to illustrate the format() method:
formatted array : 4.2
pattern is null Exception thrown : java.lang.NullPointerException
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.