String interpolation: Difference between revisions

Content deleted Content added
Python: Tighten up: no need to explain all the fmt alternatives.
Java: Clearly state that Java does not have interpolated strings, and uses formatting instead. Remove misleading code, since that is *not* interpolation.
Line 147:
=== Java ===
{{Main article|Java (programming language)}}
{{as of|2022}}, Java does not have interpolated strings, and instead uses format functions, notably the <code>MessageFormat</code> class (Java version 1.1 and above) and the static method <code>String.format</code> (Java version 5 and above).
Lacking true interpolated strings, Java uses helper functions as a workaround.
 
In Java versions 5 and above, the static method <code>String.format</code> can be used for interpolation:
<syntaxhighlight lang="java">
int apples = 4;
int bananas = 3;
System.out.println(String.format("I have %s apples and %s bananas", apples, bananas));
System.out.println(String.format("I have %s fruit", apples + bananas));
</syntaxhighlight>
 
In Java version 1.1 and above, the <code>MessageFormat</code> class can format sets of objects using placeholders:
 
<syntaxhighlight lang="java">
Object[] testArgs = {Long.valueOf(3), "MyDisk"};
 
MessageFormat form = new MessageFormat(
"The disk \"{1}\" contains {0} file(s).");
 
System.out.println(form.format(testArgs));
</syntaxhighlight>
 
=== JavaScript ===