Make sure you use a good IDE so that you have easy access to browse into JDK source code. In Eclipse say, use F3 to open to any declaration. IntelliJ IDEA has similar feature.

If you view the source code for both methods, you can see these calls are identical except that variables this is interchanged with format when comparing the instance vs static method:

public String formatted(Object... args) {
    return new Formatter().format(this, args).toString();
}
public static String format(String format, Object... args) {
    return new Formatter().format(format, args).toString();
}

So as you've observed: String.format(str, args) is same as str.formatted(args)

Answer from DuncG on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Formatter.html
Formatter (Java Platform SE 8 )
July 21, 2026 - This class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output. Common Java types such as byte, BigDecimal, and Calendar are supported. Limited formatting customization for arbitrary user types is provided ...
🌐
W3Schools
w3schools.com › java › ref_string_format.asp
Java String format() Method
Java Examples Java Videos Java ... Yourself" examples at the bottom of this page. The format() method returns a formatted string using a locale, format and additional arguments....
Discussions

What's the difference between String.format() and str. ...
To me, String::formatted feels much more ergonomic. It is also easier to type with an LSP. Using the outdated String.format is more clunky and verbose. Mr. Polywhirl – Mr. Polywhirl · 2025-04-08 21:15:33 +00:00 Commented Apr 8, 2025 at 21:15 ... equivalent by specification - from the javadoc of ... More on stackoverflow.com
🌐 stackoverflow.com
How to format strings in Java - Stack Overflow
The most frequent way to format a String is using this static method, that is long available since Java 5 and has two overloaded methods: ... The method is easy to use and the format pattern is defined by underlying formatter. More on stackoverflow.com
🌐 stackoverflow.com
String.format() is 3x faster in Java 17
Glad to see some of the small enhancements we did in 17 get recognition. Not sure if this one matters, but String::format shows up in profiles every now and then so it felt reasonable to me to give it some TLC in between larger projects. More on reddit.com
🌐 r/java
41
298
October 30, 2021
formatter - Understanding the $ in Java's format strings - Stack Overflow
Those are positional arguments ... strings for localization where arguments need to be reordered without touching the source code. The format specifiers for types which are used to represents dates and times have the following syntax: ... The optional argument_index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by "1$", the second by "2$", etc. —Formatter ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Kansas State University
textbooks.cs.ksu.edu › cc210 › 09-strings › 06-java › 04-formatting
String Formatting :: CC 210 Textbook
3 weeks ago - Java also includes a special string method, the format() method, which allows us to use placeholders in our output string, and then replace those placeholders with the values stored in variables.
Top answer
1 of 2
37

Make sure you use a good IDE so that you have easy access to browse into JDK source code. In Eclipse say, use F3 to open to any declaration. IntelliJ IDEA has similar feature.

If you view the source code for both methods, you can see these calls are identical except that variables this is interchanged with format when comparing the instance vs static method:

public String formatted(Object... args) {
    return new Formatter().format(this, args).toString();
}
public static String format(String format, Object... args) {
    return new Formatter().format(format, args).toString();
}

So as you've observed: String.format(str, args) is same as str.formatted(args)

2 of 2
22

Text Blocks were finalized and permanently added in JDK 15 and some additional methods added to support text blocks. One of this methods is:

String::formatted(Object... args)

And I know the functions of two codes below are the same.

As you mentioned in your question both methods do the same job and return same results. The goal of introducing such a method is:

simplify value substitution in the Text Block.

Based on JEP (JDK Enhancement Proposals) 378:

Text blocks do not directly support string interpolation. Interpolation may be considered in a future JEP. In the meantime, the new instance method String::formatted aids in situations where interpolation might be desired.

As an example you consider this code segment:

String code = String.format("""
      public void print(%s o) {
          System.out.println(Objects.toString(o));
      }
      """, type);

We can change it using formatted method as:

String source = """
        public void print(%s object) {
            System.out.println(Objects.toString(object));
        }
        """.formatted(type);

Which is cleaner.



Also consider these minor differences between them when using the methods:

public static String format(String format, Object... args)
  • Returns a formatted string using the format string and arguments.
  • It's a static method of String class.
  • It's introduced in Java SE 5 [since 2004].

public String formatted(Object... args)
  • Formats using this string as the format string, and the supplied arguments.
  • It's an instance method of String class.
  • It's introduced in Java SE 15 (JDK 15) [since 2020].
  • This method is equivalent to String.format(this, args)
🌐
Jmu
wiki.cs.jmu.edu › reference › java › formatting
Formatting Strings and Output in Java - JMU CS Wiki
January 26, 2026 - int year = 2017; double sales = 1050987.00; String s; s = String.format("Year: M, Sales: $%,14.2f", year, sales); After this code is executed, s will contain %%Year: 2017, Sales: $ 1,050,987.00%% Obviously, once you have a formatted String there are many things that you can do with it, including printing it (e.g., with either the print() or println() methods, both of which have a single String parameter.
Top answer
1 of 12
323

Take a look at String.format. Note, however, that it takes format specifiers similar to those of C's printf family of functions -- for example:

String.format("Hello %s, %d", "world", 42);

…would return "Hello world, 42". The "format string" link points to the complete official spec, but for simple cases, this much shorter documentation may be helpful for an introduction to format specifiers even though it's outdated and about Lava. The most commonly used ones are:

  • %s - insert a string
  • %d - insert a signed integer (decimal)
  • %f - insert a real number, standard notation

This is radically different from C#, which uses positional references with an optional format specifier. That means that you can't do things like:

String.format("The {0} is repeated again: {0}", "word");

... without actually repeating the parameter passed to printf/format. (see The Scrum Meister's comment below)


If you just want to print the result directly, you may find System.out.printf (PrintStream.printf) to your liking.

2 of 12
182

In addition to String.format, also take a look java.text.MessageFormat. The format less terse and a bit closer to the C# example you've provided and you can use it for parsing as well.

For example:

int someNumber = 42;
String someString = "foobar";
Object[] args = {new Long(someNumber), someString};
MessageFormat fmt = new MessageFormat("String is \"{1}\", number is {0}.");
System.out.println(fmt.format(args));

A nicer example takes advantage of the varargs and autoboxing improvements in Java 1.5 and turns the above into a one-liner:

MessageFormat.format("String is \"{1}\", number is {0}.", 42, "foobar");

MessageFormat is a little bit nicer for doing i18nized plurals with the choice modifier. To specify a message that correctly uses the singular form when a variable is 1 and plural otherwise, you can do something like this:

String formatString = "there were {0} {0,choice,0#objects|1#object|1<objects}";
MessageFormat fmt = new MessageFormat(formatString);
fmt.format(new Object[] { new Long(numberOfObjects) });
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-format-method-with-examples
Java String format() Method - GeeksforGeeks
June 2, 2026 - The String.format() method in Java is used to create formatted strings by combining text with values in a specified format.
🌐
CodeSignal
codesignal.com › learn › courses › java-string-manipulation-for-beginners › lessons › string-formatting-in-java-enhancing-readability-of-your-data
String Formatting in Java: Enhancing Readability of Your ...
int number = 10; // `d` specifies the number will be returned with 5 characters in it, extra digits will be filled with 0 String formatted = String.format("Number [d]", number); System.out.println(formatted); // Prints: Number [00010] This is particularly useful when numbers need to align to the right and have the same number of digits. Java provides printf, an alternative to String.format, for string formatting.
🌐
Baeldung
baeldung.com › home › java › java string › java string.format()
Java String.format() | Baeldung
March 23, 2026 - The String.format() method also enables the use of multiple format specifiers in one go, which produces a single string that contains the formatted values: String multipleFormat = String.format( "Boolean: %b, Character: %c, Decimal: %d, Hex: %x, Float: %.2f, Exponential: %e", boolValue, charValue, intValue, intValue, floatValue, floatValue ); assertEquals("Boolean: true, Character: A, Decimal: 255, Hex: ff, Float: 123.46, Exponential: 1.234568e+02", multipleFormat);
🌐
Medium
medium.com › kwal-it › how-to-format-a-string-in-java-950d07ea8be6
How To Format A String in Java. Formatted is the new kid in town | by Dieter Jordens | Kwal-IT | Medium
May 2, 2024 - Since Java 15, you can now format a String with a new method, formatted. This method is the same as the well know static String format method.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-format-a-Java-String-with-printf-example
How to format a Java String with printf in Java 25
Compare Stream distinct, HashSet, LinkedHashSet and custom-loop approaches, with modern Java 25 syntax and IO.println output. ... Use %d format specifiers, String.formatted and Java 25's IO class to add grouping, signs, alignment and padding to integer output.
Published: December 8, 2025
🌐
DZone
dzone.com › coding › java › formatting strings in java: string.format() method
Formatting Strings in Java: String.format() Method
November 13, 2024 - There are three primary ways to format a string in Java. You can use the String.format() method, the printf() method, or the MessageFormat class for formatting strings.
🌐
Codecademy
codecademy.com › docs › java › strings › .format()
Java | Strings | .format() | Codecademy
May 29, 2025 - In Java, the .format() method returns a formatted string using the specified format string and arguments.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › numberformat.html
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
Further detail can be found in the Basic I/O section of the Essential trail, in the "Formatting" page. Using String.format to create strings is covered in Strings. You can use the java.text.DecimalFormat class to control the display of leading and trailing zeros, prefixes and suffixes, grouping (thousands) separators, and the decimal separator.
🌐
Dot Net Perls
dotnetperls.com › format-java
Java - String.format Examples - Dot Net Perls
import java.util.Calendar; public class Program { public static void main(String[] args) { // Create a calendar with a specific date. Calendar cal = Calendar.getInstance(); cal.set( ... 15); // Format the month, day and year into a string. String result = String.format("Month: %1$tB Day: %1$te Year: %1$tY", cal); System.out.println(result); } } ... This example shows various ways of formatting months, days, and years with String.format.
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › use-string-format-java-string-output
Java String formatting with the String.format method (like ‘sprintf’) | alvinalexander.com
July 30, 2024 - One way to format Java string output is with the format method of the String class, which works like a “Java sprintf” method.
🌐
Reddit
reddit.com › r/java › string.format() is 3x faster in java 17
r/java on Reddit: String.format() is 3x faster in Java 17
October 30, 2021 - Yes, String::formatted is just a non-static variant of String::format. So this optimization applies equally to both. ... That's pretty cool. Highest version Java I've ever seen in the wild in Fortune 500 software is 11. Next project for me is in 8.
🌐
Dadroit
dadroit.com › online string to json converter
Online String to JSON Converter
To convert String to JSON, visit the tool address, input your String data —or load your String file— and the tool will display the corresponding JSON output in real time.