The string template was a preview feature in Java 21 and Java 22, and has been withdrawn for further redesign. In other words, this feature never existed in mainline Java (you needed to enable preview features to use it), and now with the release of Java 23, it doesn't exist at all.

If you get recommendations from IntelliJ to use string templates, you either need to update IntelliJ (it shouldn't suggest this at all for Java 23), or possibly you have set your language level to "21 (Preview)" or "22 (Preview)", instead of normal (non-preview) language level "21", "22" or "23". In other words, go to File, Project Structure, and on Project check the language level, and double-check for individual Modules (on their "Sources" tab).

As an aside, recent Java versions already optimize string concatenation like "The capital city of " + index + " is " pretty well by replacing it with a low-level form of templating in the compiled bytecode.

Answer from Mark Rotteveel on Stack Overflow
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ java โ€บ javase โ€บ 21 โ€บ language โ€บ string-templates.html
4 String Templates
January 16, 2025 - String templates complement Java's existing string literals and text blocks by coupling literal text with embedded expressions and template processors to produce specialized results. An embedded expression is a Java expression except it has additional syntax to differentiate it from the literal ...
Discussions

String Templates. Then What?
I'm aware that the String Template JEP is still in the early phase. You are aware that they have been pulled completely for now? More on reddit.com
๐ŸŒ r/java
64
21
February 9, 2025
There will be no String Template in JDK 23.
wow. It's interesting that Brian Goetz recently said he was ready to finalize the feature and move on, and all the complaints were nothing they hadn't anticipated and discussed extensively. They had the JEP submitted to finalize this for Java 22 and they held off to a second unchanged preview, and then were going to finalize for Java 23, and now, even Goetz is ready to move the whole thing back to a complete redesign. As a Java dev I'd rather get this later with a better design than earlier with a less perfect design. It is interesting how close the existing design was to being finalized. The preview system works :) More on reddit.com
๐ŸŒ r/java
131
122
April 6, 2024
Why does Java's string templating use clumsy STR prefix? - Stack Overflow
Java finally supports string interpolation! I'm very happy about it. However, the syntax seems to me a bit clumsy // string templating syntax from Java 23 String greeting = STR."Hello \{name}... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What Happened to Java's String Templates? Inside Java Newscast
Honestly, this whole thing with string templates in java feels like a paranoia. Security? Validation? The hell are they smokin there? Why are they trying to solve world hunger with it? Just give people the damn interpolation like all normal human beings have other languages that's all we want. More on reddit.com
๐ŸŒ r/java
122
66
May 10, 2024
๐ŸŒ
OpenJDK
openjdk.org โ€บ jeps โ€บ 465
JEP 465: String Templates (Third Preview)
January 9, 2024 - Ideally a string's template could be expressed directly in the code, as if annotating the string, and the Java runtime would apply template-specific rules to the string automatically. The result would be SQL statements with escaped quotes, HTML documents with no illegal entities, and boilerplate-free message localization.
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ string templates. then what?
r/java on Reddit: String Templates. Then What?
February 9, 2025 -

It's weekend, so...

I'm aware that the String Template JEP is still in the early phase. But I'm excited about the future it will bring. That is, not a mere convenient String.format(), but something far more powerful that can be used to create injection-safe higher-level objects.

Hypothetically, I can imagine JDBC API being changed to accept StringTemplate, safely:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  var results = connection.query(
      // Evaluates to a StringTemplate
      // parameters passed through PreparedStatement
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """);
}

We would be able to create dynamic SQL almost as if they were the golden gold days' static SQL. And the SQL will be 100% injection-proof.

That's all good. What remains unclear to me though, is what to do with the results?

The JDBC ResultSet API is weakly typed, and needs the programmer to call results.getString("UserId"), results.getDate("BirthDay").toLocalDate() etc.

Honestly, the lack of static type safety doesn't bother me much. With or without static type safety, for any non-trivial SQL, I wouldn't trust the correctness of the SQL just because it compiles and all the types match. I will want to run the SQL against a hermetic DB in a functional test anyways, and verify that given the right input, it returns the right output. And when I do run it, the column name mismatch error is the easiest to detect.

But the ergonomics is still poor. Without a standard way to extract information out of ResultSet, I bet people will come up with weird ways to plumb these data, some are testable, and some not so much. And people may then just give up the testing because "it's too hard".

This seems a nice fit for named parameters. Java currently doesn't have it, but found this old thread where u/pron98 gave a nice "speculation". Guess what? 3 years later, it seems we are really really close. :-)

So imagine if I could define a record for this query:

record UserData(String userId, LocalDate birthDate, String email) {}

And then if JDBC supports binding with named parameters out of box, the above code would be super easy to extract data out of the ResultSet:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  List<UserData> userDataList = connection.query(
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """,
      UserData.class);
}

An alternative syntax could use lambda:

List<String> userIds = ...;
UserStatus = ...;
try (var connection = DriverManager.getConnection(...)) {
  List<UserData> userDataList = connection.query(
      """
      SELECT UserId, BirthDate, Email from Users
      WHERE UserId IN (\{userIds}) AND status = \{userStatus}
      """,
     (String userId, LocalDate birthDate, String email) ->
         new UserData() with {
             .userId = userId, .birthDate = birthDate, .email = email});
}

But:

  1. It's verbose

  2. The SQL can select 12 columns. Are we really gonna create things like Function12<A, B, C, ..., K, L> ?

And did I say I don't care much about static type safety? Well, I take it back partially. Here, if compiler can help me check that the 3 columns match in name with the proeprties in the UserData class, that'd at least help prevent regression through refactoring (someone renames the property without knowing it breaks the SQL).

I don't know of a precedent in the JDK that does such thing - to derive static type information from a compile-time string constant. But I suppose whatever we do, it'd be useful if JDK provides a standard API that parses SQL string template into a SQL AST. Then libraries, frameworks will have access to the SQL metadata like the column names being returned.

If a compile-time plugin like ErrorProne parses out the column names, it would be able to perform compile-time checking between the SQL and the record; whereas if the columns are determined at runtime (passed in as a List<String>), it will at least use reflection to construct the record.

So maybe it's time to discuss such things beyond the JEP? I mean, SQL is listed as a main use case behind the design. So might as well plan out for the complete programmer journey where writing the SQL is the first half of the journey?

Forgot to mention: I'm focused on SQL-first approach where you have a SQL and then try to operate it in Java code. There are of course O-R frameworks like JPA, Hibernate that are model-first but I haven't needed that kind of practice yet so I dunno.

What are your thoughts?

๐ŸŒ
Medium
medium.com โ€บ javarevisited โ€บ jdk-25-the-new-features-in-java-25-2366dc2f994f
JDK 25 โ€” The New Features in Java 25 | by Harry | Javarevisited | Medium
August 13, 2025 - JDK 25 โ€” The New Features in Java 25 Why Java 25 is not just another version number โ€” and why you should care (even if you think you donโ€™t) A few weeks ago, I opened up some old Java code from โ€ฆ
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ string templates in java
String Templates in Java | Baeldung
July 7, 2025 - The same is followed for โ€œโ€โ€<some text>โ€โ€โ€ to distinguish between TextBlock and TextBlockTemplate. This distinction is important to Java because, even though in both cases itโ€™s wrapped between double quotes(โ€œโ€), a String template is of type java.lang.StringTemplate, an interface, and not the java.lang.String.
๐ŸŒ
HappyCoders.eu
happycoders.eu โ€บ java โ€บ string-templates
String Templates in Java
June 12, 2025 - Learn how String Templates in Java simplify the composition of strings from text, variables and calculated values.
Find elsewhere
๐ŸŒ
nipafx
nipafx.dev โ€บ inside-java-newscast-71
What Happened to Java's String Templates? Inside Java Newscast #71 // nipafx
And as we've touched on in the last Inside Java Newscast, that's exactly what happened: JDK 23 contains no string templates at all and once you update your experimental and hobby code bases, you'll have to rip out everything related to string ...
Published ย  June 20, 2024
๐ŸŒ
YouTube
youtube.com โ€บ watch
Java 25 String Templates Explained ๐Ÿ”ฅ | Clean & Modern Way to Build Strings! #shorts - YouTube
Say goodbye to messy string concatenations! ๐Ÿš€Java 25 introduces String Templates โ€” a modern way to build readable, clean, and elegant strings.Now you can em...
Published ย  October 24, 2025
๐ŸŒ
JetBrains
blog.jetbrains.com โ€บ idea โ€บ 2023 โ€บ 11 โ€บ string-templates-in-java-why-should-you-care
String Templates in Java - why should you care? | The IntelliJ IDEA Blog
November 27, 2023 - TLDR; The existing String concatenation ... (a preview feature introduced in Java 21) greatly improves how we create strings in Java by merging constant strings with variable values....
๐ŸŒ
Medium
maffonso.medium.com โ€บ java-string-templates-simplifying-text-handling-1f36f864056e
Java String Templates: Simplifying Text Handling | by Mauricio Afonso | Medium
June 14, 2024 - To understand String Templates, we must start by talking about the structure of this feature. Template Processor + Template + Template Expressions ... mechanism that will process the text STR is a template processor defined in the Java Platform.
๐ŸŒ
Codeline24
codeline24.com โ€บ home โ€บ java string templates
Java String Templates - Java and Spring Trends
September 5, 2024 - Reduced Errors: By eliminating the need for index-based placeholders (as in String.format()), string templates reduce the likelihood of formatting errors. Type Safety: The Java compiler can perform type checking on the expressions within the templates, catching potential type mismatches at compile-time rather than runtime.
๐ŸŒ
Java Almanac
javaalmanac.io โ€บ features โ€บ stringtemplates
String Templates (JEP 430, 459, 465, withdrawn) - javaalmanac.io
The FMT processor yields a String, but the RAW processor yields an object of the class StringTemplate. Here is a sandbox with these examples. Try adding a space before or after a format specifier. Also try reassigning item after the raw template was formed. Are the values updated? Should they be? import static java.util.FormatProcessor.FMT; import static java.lang.StringTemplate.RAW; public class TemplateProcessors { record Item(String description, int quantity, double price) {} public static void main(String[] args) { var item = new Item("Blackwell Toaster", 2, 29.95); String line = FMT."%-20s\{item.description()} | ]\{item.quantity()} | .2f\{item.price()}%n"; System.out.print(line); item = new Item("Zappa Microwave Oven", 1, 109.95); // TODO What happens if you add a space before or after %-20s?
๐ŸŒ
OpenJDK
openjdk.org โ€บ jeps โ€บ 430
JEP 430: String Templates (Preview)
September 17, 2021 - Ideally a string's template could be expressed directly in the code, as if annotating the string, and the Java runtime would apply template-specific rules to the string automatically. The result would be SQL statements with escaped quotes, HTML documents with no illegal entities, and boilerplate-free message localization.
๐ŸŒ
Kodejava
kodejava.org โ€บ how-to-write-cleaner-code-with-string-templates-in-java
How to Write Cleaner Code with String Templates in Java - Learn Java by Examples
String templates allow you to define a string that contains placeholders for expressions. These placeholders are evaluated at runtime. In Java 25, this is done using the STR.""" syntax (or StringTemplate API).
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ java โ€บ javase โ€บ 21 โ€บ docs โ€บ api โ€บ java.base โ€บ java โ€บ lang โ€บ StringTemplate.html
StringTemplate (Java SE 21 & JDK 21)
January 20, 2026 - In the source code of a Java program, a string template or text block template contains an interleaved succession of fragment literals and embedded expressions. The fragments() method returns the fragment literals, and the values() method returns the results of evaluating the embedded expressions.