What is the difference between `String.format()` and `String.formatted()` (Java 15+)?

Java Professional Medium

Java Professional — Medium

What is the difference between `String.format()` and `String.formatted()` (Java 15+)?

Key points

  • `format()` is a static factory method
  • `formatted()` is an instance method on String
  • Both methods serve the same purpose
  • `format()` is used to create formatted strings
  • `formatted()` is a more convenient way to achieve the same result

Ready to go further?

Related questions