Java String format()The java string format() method returns the formatted string by given locale, format and arguments. If you don't specify the locale in String.format() method, it uses default locale by calling Locale.getDefault() method. The format() method of java language is like sprintf() function in c language and printf() method of java language. Internal implementationSignatureThere are two type of string format() method: Parameterslocale : specifies the locale to be applied on the format() method. format : format of the string. args : arguments for the format string. It may be zero or more. Returnsformatted string ThrowsNullPointerException : if format is null. IllegalFormatException : if format is illegal or incompatible. Java String format() method exampleTest it Nowname is sonoo value is 32.334340 value is 32.334340000000 Java String Format SpecifiersHere, we are providing a table of format specifiers supported by the Java String.
Java String format() Method Example 2This method supports various data types and formats them into a string type. Let us see an example. Test it Now101 Amar Singh 101.000000 65 c Java String format() Method Example 3Apart from formatting, we can set width, padding etc. of any value. Let us see an example where we are setting width and padding for an integer value. Test it Now101 | 101| |101 | | 101| |0000000101| Next TopicJava String getBytes() |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India