If you're using Java 5 or higher, you can use String.format:

urlString += String.format("u1=%s;u2=%s;u3=%s;u4=%s;", u1, u2, u3, u4);

See Formatter for details.

Answer from Jon Skeet on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › string interpolation in java
String Interpolation in Java | Baeldung
July 23, 2025 - String interpolation is a straightforward and precise way to inject variable values into a string. It allows users to embed variable references directly in processed string literals.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-illustrate-string-interpolation
String Interpolation in Java - GeeksforGeeks
July 23, 2025 - Below is the simplest way to do string interpolation using "+" operator in Java.
Top answer
1 of 5
442

If you're using Java 5 or higher, you can use String.format:

urlString += String.format("u1=%s;u2=%s;u3=%s;u4=%s;", u1, u2, u3, u4);

See Formatter for details.

2 of 5
147

Edit March 2024

Many things have changes for the past ten years. Java currently has JEP 430: String Templates in the preview feature (Java 21 & Java 22). String templates are not equivalent to string interpolation, but they support it. String templates are much more powerful than traditional string interpolations in C#, Perl, or Python.

String templates have built-in string processors (STR and FMT) and also allow to create custom template processors. They are, according to the documentation, safer (or allow to create safer code more easily).

import static java.util.FormatProcessor.FMT;

void main() {

    int age = 34;
    String name = "William";

    String msg = STR."\{name} is \{age} years old";
    System.out.println(msg);

    String msg2 = FMT."%s\{name} is %d\{age} years old";
    System.out.println(msg2);
}

The example demonstrates the usage of STR and FMT processors. The latter must be explicitly imported.

From the JEP:

STR is a template processor defined in the Java Platform. It performs string interpolation by replacing each embedded expression in the template with the (stringified) value of that expression.

FMT is another template processor defined in the Java Platform. FMT is like STR in that it performs interpolation, but it also interprets format specifiers which appear to the left of embedded expressions.

In essence, Java now supports string interpolation in preview within a more powerful concept called string templates.

The following information is outdated now and reflects the situation before Java 21:

Note that there is no variable interpolation in Java. Variable interpolation is variable substitution with its value inside a string. An example in Ruby:

#!/usr/bin/ruby

age = 34
name = "William"

puts "#{name} is #{age} years old"

The Ruby interpreter automatically replaces variables with its values inside a string. The fact, that we are going to do interpolation is hinted by sigil characters. In Ruby, it is #{}. In Perl, it could be $, % or @. Java would only print such characters, it would not expand them.

Variable interpolation is not supported in Java. Instead of this, we have string formatting.

package com.zetcode;

public class StringFormatting 
{
    public static void main(String[] args) 
    {
        int age = 34;
        String name = "William";

        String output = String.format("%s is %d years old.", name, age);
    
        System.out.println(output);
    }
}

In Java, we build a new string using the String.format() method. The outcome is the same, but the methods are different.

See http://en.wikipedia.org/wiki/Variable_interpolation

Edit As of 2019, JEP 326 (Raw String Literals) was withdrawn and superseded by multiple JEPs eventually leading to JEP 378: Text Blocks delivered in Java 15.

A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired.

However, still no string interpolation:

Non-Goals: … 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.

🌐
Medium
medium.com › @viraj_63415 › java-21-string-templates-79fd908f30ff
Java String Templates — A Better Interpolation | by Viraj Shetty | Medium
June 19, 2024 - There are several inbuilt Template Processors available in Java. STR is one of the inbuilt Template Processors that can be used to evaluate the String Template. Apart from STR, there are two other Template Processors available — FMT and RAW. FMT performs String interpolation but it also interprets format specifiers which appear to the left of embedded expressions.
🌐
NamasteDev
namastedev.com › learn › namaste-dsa
Namaste DSA - Learn Data Structures & Algorithms from scratch
Although the instructor uses JavaScript for code explanation. ... The course covers all fundamental data structures including arrays, linked lists, stacks, queues, trees, binary search trees, heaps, graphs, hash tables, and advanced structures needed for coding interviews. ... Namaste DSA covers searching, sorting, recursion, dynamic programming, greedy algorithms, backtracking, graph algorithms, string algorithms, and various problem-solving techniques essential for coding interviews.
Find elsewhere
🌐
Reddit
reddit.com › r/programming › java string interpolation final in java 23
r/programming on Reddit: Java String Interpolation final in Java 23
January 13, 2024 - The syntax is really ugly, but it's nice to finally get string interpolation in regular old Java.
🌐
DEV Community
dev.to › sharique_siddiqui_8242dad › understanding-string-interpolation-in-java-34ch
Understanding String Interpolation in Java - DEV Community
July 30, 2025 - In the world of programming, string interpolation is a handy feature that allows developers to embed variables directly into strings. It makes code more readable, concise, and easier to maintain. While many languages like Python, JavaScript, and Kotlin have built-in support for string interpolation using symbols like $ or {}, Java doesn’t support native string interpolation — yet.
🌐
Oracle
docs.oracle.com › cd › E19146-01 › 820-1062 › abvaw › index.html
String Interpolation (Sun Java System Web Server 7.0 Update 1 Administrator's Configuration File Reference)
Sun Java System Web Server 7.0 Update 1 Administrator's Configuration File Reference ... Strings that contain references to variables or expressions are called interpolated strings. When you use interpolated strings, the embedded expressions and variables are evaluated and the result is inserted ...
🌐
Medium
medium.com › @ujjawalr › string-interpolation-in-java-4a6571111f2d
String interpolation in java. String interpolation is a process of… | by Ujjawal Rohra | Medium
March 6, 2023 - String interpolation in java String interpolation is a process of inserting values into a string template at run-time. This can be useful when you need to insert values into a string that is being …
🌐
Simplilearn
simplilearn.com › home › resources › software development › angular tutorial for beginners › angular interview questions and answers 2026
Angular Interview Questions and Answers 2026
4 weeks ago - Prepare for an Angular interview with scenario-based questions on code scenarios, architecture decisions, migrations, testing, and scaling patterns.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
GitHub
github.com › lantunes › interpolatd
GitHub - lantunes/interpolatd: A string interpolation library for Java
Interpolatd is a string interpolation library for Java. It aspires to be easy to use and yet flexible and powerful.
Starred by 12 users
Forked by 3 users
Languages   Java 100.0% | Java 100.0%
🌐
OpenJDK
openjdk.org › jeps › 459
JEP 459: String Templates (Second Preview)
August 14, 2023 - Template expressions are a new kind of expression in the Java programming language. Template expressions can perform string interpolation but are also programmable in a way that helps developers compose strings safely and efficiently.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › csharp › language-reference › tokens › interpolated
$ - string interpolation - format string output - C# reference | Microsoft Learn
January 14, 2026 - If you're new to string interpolation, see the String interpolation in C# tutorial. That tutorial demonstrates how to use interpolated strings to produce formatted strings. The compiler checks if an interpolated string is assigned to a type that satisfies the interpolated string handler pattern.
🌐
DEV Community
dev.to › nermin_karapandzic › string-interpolation-in-java-finally-74g
String Interpolation in Java, finally - DEV Community
December 3, 2023 - STR is a template processor included in the Java platform. It performs string interpolation by replacing each embedded expression in the template with the (stringified) value of that expression.
🌐
Tutorialspoint
tutorialspoint.com › java › java_strings.htm
Java - String Class
Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object.
🌐
GitHub
microsoft.github.io › monaco-editor
Monaco Editor
The index of Microsoft GitHub repositories that are open source has been relocated to https://opensource.microsoft.com