You can use Java's String Templates feature.
It is described in JEP 430, and it appears in JDK 21 as a preview feature. Here is an example use:
String s = STR."Date: \{new DateTime()}";
A string template can interpolate arbitrary code, which may contain newlines and comments that won't show up in the final string:
String time = STR."The time is \{
// This does custom formatting.
DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now())
} right now";
Java's string templates are more versatile, and much safer, than features in other languagues such as C#'s string interpolation and Python's f-strings.
For example, string concatenation or interpolation makes SQL injection attacks possible:
String query = "SELECT * FROM Person p WHERE p.last_name = '" + name + "'";
ResultSet rs = conn.createStatement().executeQuery(query);
but this variant (from JEP 430) prevents SQL injection:
PreparedStatement ps = DB."SELECT * FROM Person p WHERE p.last_name = \{name}";
ResultSet rs = ps.executeQuery();