{"id":5690,"date":"2023-09-29T07:01:39","date_gmt":"2023-09-29T06:01:39","guid":{"rendered":"https:\/\/www.baeldung.com\/java-21-string-templates"},"modified":"2023-09-29T07:01:39","modified_gmt":"2023-09-29T06:01:39","slug":"string-templates-in-java-21","status":"publish","type":"post","link":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/2023\/09\/29\/string-templates-in-java-21\/","title":{"rendered":"String Templates in Java 21"},"content":{"rendered":"<p><img src=\"https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-1024x536.png\" class=\"webfeedsFeaturedVisual wp-post-image\" alt=\"\" decoding=\"async\" style=\"float: left; margin-right: 5px;\" loading=\"lazy\" srcset=\"https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-1024x536.png 1024w, https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-300x157.png 300w, https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-768x402.png 768w, https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-100x52.png 100w, https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured.png 1200w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/p>\n<h2 id=\"bd-introduction\" data-id=\"introduction\">1. Introduction<\/h2>\n<div class=\"bd-anchor\" id=\"introduction\"><\/div>\n<p>In this tutorial, we&#8217;ll talk about Java&#8217;s answer to String interpolation &#8211; String templates. This pre-release preview feature was introduced as part of Java 21 with <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/openjdk.org\/jeps\/430\">JEP 430<\/a>.<\/p>\n<h2 id=\"bd-string-composition-in-java\" data-id=\"string-composition-in-java\">2. String Composition in Java<\/h2>\n<div class=\"bd-anchor\" id=\"string-composition-in-java\"><\/div>\n<p>We use <em>Strings<\/em> to represent sequences of numbers, letters, and symbols to represent text in code. <em>Strings<\/em> are ubiquitous in programming, and we often need to compose strings to use in code. There are several ways to do that, and each technique has its downsides.<\/p>\n<h3 id=\"bd-1-string-concatenation\" data-id=\"1-string-concatenation\">2.1. String Concatenation<\/h3>\n<div class=\"bd-anchor\" id=\"1-string-concatenation\"><\/div>\n<p><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/java-strings-concatenation\">String concatenation<\/a> is the most basic action we use to build strings. We take strings literals and expressions and then use the <em>+<\/em> symbol to compose them together:<\/p>\n<pre><code class=\"language-java\">String composeUsingPlus(String feelsLike, String temperature, String unit){\r\n    return &quot;Today&#039;s weather is &quot; + feelsLike + \r\n      &quot;, with a temperature of &quot; + temperature + &quot; degrees &quot; + unit;\r\n}<\/code><\/pre>\n<p><strong>This code achieves the desired functionality but is hard to read, especially with all the plus symbols, and also difficult to maintain and change.<\/strong><\/p>\n<h3 id=\"bd-2-stringbuffer-or-stringbuilder\" data-id=\"2-stringbuffer-or-stringbuilder\">2.2. <em>StringBuffer<\/em> or <em>StringBuilder<\/em><\/h3>\n<div class=\"bd-anchor\" id=\"2-stringbuffer-or-stringbuilder\"><\/div>\n<p>We can use utility classes Java provides, such as the<a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/java-string-builder-string-buffer\"> <em>StringBuilder<\/em> and <em>StringBuffer<\/em><\/a> classes. These classes provide us with the <em>append()\u00a0<\/em>library function to compose strings, thereby removing the usage of <em>+ <\/em>in string composition:<\/p>\n<pre><code class=\"language-java\">String composeUsingStringBuilder(String feelsLike, String temperature, String unit) {\r\n    return new StringBuilder()\r\n      .append(&quot;Today&#039;s weather is &quot;)\r\n      .append(feelsLike)\r\n      .append(&quot;, with a temperature of &quot;)\r\n      .append(temperature)\r\n      .append(&quot; degrees &quot;)\r\n      .append(unit)\r\n      .toString();\r\n}<\/code><\/pre>\n<p><em>StringBuilder<\/em> and <em>StringBuffer<\/em> classes provide efficient String manipulation and composition techniques while reducing memory overheads. <strong>However, they follow the <em>Builder<\/em> design pattern and hence become quite verbose.<\/strong><\/p>\n<h3 id=\"bd-3-string-formatter\" data-id=\"3-string-formatter\">2.3. String Formatter<\/h3>\n<div class=\"bd-anchor\" id=\"3-string-formatter\"><\/div>\n<p>Java provides us with the capability to separate the static part of the String and the parameters, such as the <em>temperature<\/em> and the <em>unit<\/em> with the <em><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/string\/format\">String.format()<\/a> <\/em>or the <em>formatted()<\/em> methods:<\/p>\n<pre><code class=\"language-java\">String composeUsingFormatters(String feelsLike, String temperature, String unit) {\r\n    return String.format(&quot;Today&#039;s weather is %s, with a temperature of %s degrees %s&quot;, \r\n      feelsLike, temperature, unit);\r\n}<\/code><\/pre>\n<p><strong>The base template string remains static. However, the order and the number of arguments passed here are crucial for the correctness of its response.<\/strong><\/p>\n<h3 id=\"bd-4-messageformat-class\" data-id=\"4-messageformat-class\">2.4. <em>MessageFormat<\/em> class<\/h3>\n<div class=\"bd-anchor\" id=\"4-messageformat-class\"><\/div>\n<p>Java provides a <em>MessageFormat<\/em> class of the <em>Java.text<\/em> package that helps in the composition of text messages with placeholders for dynamic data. <a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/java-localization-messages-formatting\"><em>Localisation<\/em><\/a> and <em>Internationalisation<\/em> heavily use this. We can use <em>MessageFormat.format()<\/em> in plain String composition:<\/p>\n<pre><code class=\"language-java\">String composeUsingMessageFormatter(String feelsLike, String temperature, String unit) {\r\n    return MessageFormat.format(&quot;Today&#039;&#039;s weather is {0}, with a temperature of {1} degrees {2}&quot;,\r\n      feelsLike, temperature, unit);\r\n}<\/code><\/pre>\n<p>This also shares a similar downside as that of the above. Additionally, the syntax structure differs from how we write and use strings in code.<\/p>\n<h2 id=\"bd-introduction-to-string-templates\" data-id=\"introduction-to-string-templates\">3. Introduction to String Templates<\/h2>\n<div class=\"bd-anchor\" id=\"introduction-to-string-templates\"><\/div>\n<p>As we saw, all the String composition techniques mentioned above come with their shortcoming. Let&#8217;s see how String templates can help with those.<\/p>\n<h3 id=\"bd-1-goals\" data-id=\"1-goals\">3.1. Goals<\/h3>\n<div class=\"bd-anchor\" id=\"1-goals\"><\/div>\n<p>String templates are introduced to the Java programming ecosystem with the following goals in mind:<\/p>\n<ul>\n<li>Simplify the process of expressing <em>Strings<\/em> with values that can be compiled at run time<\/li>\n<li>Enhanced readability of <em>String<\/em> compositions, overcome the verbosity associated with <em>StringBuilder<\/em>\u00a0and <em>StringBuffer<\/em> classes<\/li>\n<li>Overcome the security issues of the <em>String<\/em> interpolation techniques that other programming languages allow, trading off a small amount of inconvenience<\/li>\n<li>Allow Java libraries to define custom formatting syntax of the resulting String literal<\/li>\n<\/ul>\n<h3 id=\"bd-2-template-expressions\" data-id=\"2-template-expressions\">3.2. Template Expressions<\/h3>\n<div class=\"bd-anchor\" id=\"2-template-expressions\"><\/div>\n<p>The most important concept of String templates revolves around template expressions, a new kind of programmable expressions in Java.<strong> Programmable template expressions can perform interpolation but also provide us with the flexibility to compose the Strings safely and efficiently.<\/strong><\/p>\n<p><strong>Template expressions can turn structured text into any object, not just limited to Strings.<\/strong><\/p>\n<p>There are three components to a template expression:<\/p>\n<ul>\n<li>A processor<\/li>\n<li>A template which contains the data with the embedded expressions<\/li>\n<li>A dot (.) character<\/li>\n<\/ul>\n<h2 id=\"bd-template-processors\" data-id=\"template-processors\">4. Template Processors<\/h2>\n<div class=\"bd-anchor\" id=\"template-processors\"><\/div>\n<p><strong>A template processor is responsible for evaluating the embedded expression (the template) and combines it with the <em>String<\/em> literal at runtime to produce the final <em>String<\/em>.<\/strong> Java provides the ability to use an inbuilt template processor, provided by Java, or switch it with a custom processor of our own.<\/p>\n<p>This is a preview feature in Java 21; hence, we would have to enable preview mode.<\/p>\n<h3 id=\"bd-1-str-template-processor\" data-id=\"1-str-template-processor\">4.1. <em>STR<\/em> Template Processor<\/h3>\n<div class=\"bd-anchor\" id=\"1-str-template-processor\"><\/div>\n<p>Java provides some out-of-the-box template processors.<strong> The <em>STR<\/em> Template Processor performs string interpolation by iteratively replacing each embedded expression of the provided template with the stringified value of that expression<\/strong>. We will apply the <em>STR<\/em> processor String template in our previous example here:<\/p>\n<pre><code class=\"language-java\">String interpolationUsingSTRProcessor(String feelsLike, String temperature, String unit) {\r\n    return STR\r\n      . &quot;Today&#039;s weather is \\{ feelsLike }, with a temperature of \\{ temperature } degrees \\{ unit }&quot; ;\r\n}<\/code><\/pre>\n<p><strong><em>STR\u00a0<\/em>is a public static final field and is automatically imported into every Java compilation unit.<\/strong><\/p>\n<p>We can extend the above implementation not just to single-line Strings but to multiline expressions as well. For multiline text blocks, we surround the text block with <em>&#8220;&#8221;&#8221;<\/em>. Let&#8217;s take the example of interpolating a String that represents a JSON:<\/p>\n<pre><code class=\"language-java\">String interpolationOfJSONBlock(String feelsLike, String temperature, String unit) {\r\n    return STR\r\n      . &quot;&quot;&quot;\r\n      {\r\n        &quot;feelsLike&quot;: &quot;\\{ feelsLike }&quot;,\r\n        &quot;temperature&quot;: &quot;\\{ temperature }&quot;,\r\n        &quot;unit&quot;: &quot;\\{ unit }&quot;\r\n      }\r\n      &quot;&quot;&quot; ;\r\n}<\/code><\/pre>\n<p><strong>We can also inject expressions inline, which will compile at runtime:<\/strong><\/p>\n<pre><code class=\"language-java\">String interpolationWithExpressions() {\r\n    return STR\r\n      . &quot;Today&#039;s weather is \\{ getFeelsLike() }, with a temperature of \\{ getTemperature() } degrees \\{ getUnit() }&quot;;\r\n}<\/code><\/pre>\n<h3 id=\"bd-2-fmt-template-processor\" data-id=\"2-fmt-template-processor\">4.2. <em>FMT<\/em> Template Processor<\/h3>\n<div class=\"bd-anchor\" id=\"2-fmt-template-processor\"><\/div>\n<p>Another Java-provided processor is the <em>FMT<\/em> Template Processor. <strong>It adds the support of understanding formatters that are provided to the processor and format the data according to the formatting style provided.<\/strong><\/p>\n<p>The supplied <em>formatter<\/em> should be similar to <em><a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/www.baeldung.com\/java-string-formatter\">java.util.Formatter<\/a>:<\/em><\/p>\n<pre><code class=\"language-java\">String interpolationOfJSONBlockWithFMT(String feelsLike, float temperature, String unit) {\r\n    return FMT\r\n      . &quot;&quot;&quot;\r\n      {\r\n        &quot;feelsLike&quot;: &quot;%1s\\{ feelsLike }&quot;,\r\n        &quot;temperature&quot;: &quot;%2.2f\\{ temperature }&quot;,\r\n        &quot;unit&quot;: &quot;%1s\\{ unit }&quot;\r\n      }\r\n      &quot;&quot;&quot; ;\r\n}<\/code><\/pre>\n<p><strong>Here, we use <em>%s<\/em> and <em>%f<\/em> to format the string and the temperature in a specific format.<\/strong><\/p>\n<h3 id=\"bd-3-evaluation-of-a-template-expression\" data-id=\"3-evaluation-of-a-template-expression\">4.3. Evaluation of a Template Expression<\/h3>\n<div class=\"bd-anchor\" id=\"3-evaluation-of-a-template-expression\"><\/div>\n<p>There are a few steps involved in the evaluation of a template expression in the line:<\/p>\n<pre><code class=\"language-java\">STR\r\n  . &quot;Today&#039;s weather is \\{ feelsLike }, with a temperature of \\{ temperature } degrees \\{ unit }&quot; ;<\/code><\/pre>\n<p>The above is a shorthand for several steps that we&#8217;ll see.<\/p>\n<p>First, an instance of a template processor, <em>StringTemplate.Processor&lt;R, E&gt;<\/em> is obtained by evaluating the left of the dot. In our case, it is the <em>STR<\/em> template processor.<\/p>\n<p>Next, we obtain an instance of a template, <em>StringTemplate,<\/em>\u00a0by evaluating to the right of the dot:<\/p>\n<pre><code class=\"language-java\">StringTemplate str = RAW\r\n  . &quot;Today&#039;s weather is \\{ getFeelsLike() }, with a temperature of \\{ getTemperature() } degrees \\{ getUnit() }&quot; ;<\/code><\/pre>\n<p><em>RAW<\/em> is the standard template processor which produces an unprocessed <em>StringTemplate<\/em> type object.<\/p>\n<p>Finally, we pass the <em>StringTemplate str<\/em> instance to the process() method of the processor(which in our case is <em>STR)<\/em>:<\/p>\n<pre><code class=\"language-java\">return STR.process(str);<\/code><\/pre>\n<h2 id=\"bd-string-interpolation-and-string-templates\" data-id=\"string-interpolation-and-string-templates\">5. String Interpolation and String Templates<\/h2>\n<div class=\"bd-anchor\" id=\"string-interpolation-and-string-templates\"><\/div>\n<p>We have now seen examples of using String templates as a string composition technique, and we can see that it is very similar to String interpolation. However, String templates provide the safety that String interpolation on other platforms generally does not guarantee.<\/p>\n<p><strong>Template expressions are designed intentionally so that it is impossible to interpolate a String literal or text block containing an embedded expression to an output String directly.<\/strong> The processor&#8217;s presence ensures that dangerous or incorrect Strings do not propagate through the code.<strong> It is the processor&#8217;s responsibility to validate that the interpolation is safe and correct.<\/strong><\/p>\n<p><strong>The absence of any template processor will generate a compile-time error. Also, if the processor fails to interpolate, it can generate an <em>Exception<\/em>.<\/strong><\/p>\n<p>Java decides to treat <em>&#8220;&lt;some text&gt;&#8221;<\/em> as a <em>StringLiteral<\/em> or a <em>StringTemplate<\/em> based on the presence of the embedded expressions. The same is followed for <em>&#8220;&#8221;&#8221;&lt;some text&gt;&#8221;&#8221;&#8221;<\/em> to distinguish between <em>TextBlock<\/em> and <em>TextBlockTemplate<\/em>. <strong>This distinction is important to Java because even though, in both cases, it is wrapped between double quotes(<em>&#8220;&#8221;<\/em>), a String template is of type <em>java.lang.StringTemplate,\u00a0<\/em>an interface, and<\/strong> <strong>not the <em>java.lang.String.<\/em><\/strong><\/p>\n<h2 id=\"bd-conclusion\" data-id=\"conclusion\">6. Conclusion<\/h2>\n<div class=\"bd-anchor\" id=\"conclusion\"><\/div>\n<p>In this article, we discussed several String composition techniques and understood the idea behind String interpolation. We also looked at how Java is introducing the idea of String interpolation with the help of String templates. Finally, we looked at how String templates are better and safer to use than the general String interpolation.<\/p>\n<p>As usual, the code is available\u00a0<a href=\"https:\/\/feeds.feedblitz.com\/~\/t\/0\/0\/baeldung\/~https:\/\/github.com\/eugenp\/tutorials\/tree\/master\/core-java-modules\/core-java-21\">over on GitHub<\/a>.<\/p>\n<p><Img align=\"left\" border=\"0\" height=\"1\" width=\"1\" alt=\"\" style=\"border:0;float:left;margin:0;padding:0;width:1px!important;height:1px!important;\" hspace=\"0\" src=\"https:\/\/feeds.feedblitz.com\/~\/i\/796683116\/0\/baeldung\"><\/p>\n<div style=\"clear:both;padding-top:0.2em;\"><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/796683116\/baeldung,https%3A%2F%2Fwww.baeldung.com%2Fwp-content%2Fuploads%2F2021%2F09%2FJava-8-Featured-1024x536.png\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\" style=\"border:0;margin:0;padding:0;\"><\/a>&#160;<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/java-21-string-templates#respond\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>&#160;<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/java-21-string-templates\/feed\"><img decoding=\"async\" height=\"20\" style=\"border:0;margin:0;padding:0;\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>&#160;<\/div>\n\n<h2><b>Commercials Cooperation Advertisements:<\/b><\/h2>\r\n<p><br>(1) IT Teacher IT Freelance<br> <\/p>\r\n<a href=https:\/\/itteacheritfreelance.hk\/wordpress><img src=http:\/\/gamefootballmobileanimeiphone.com\/wp-content\/uploads\/2023\/09\/ITTeacherITFreelance-Website.png alt=IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\/><\/a><p><a href=https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/findteacher>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427! <\/a><br>\r\n\r\n\u7535\u5b50\u8ba1\u7b97\u673a -\u6559\u80b2 -IT \u96fb\u8166\u73ed\u201d ( IT\u96fb\u8166\u88dc\u7fd2 ) \u63d0\u4f9b\u4e00\u500b\u65b9\u4fbf\u7684\u7535\u5b50\u8ba1\u7b97\u673a \u6559\u80b2\u5e73\u53f0, \u70ba\u5927\u5bb6\u914d\u5c0d\u4fe1\u606f\u6280\u672f, \u96fb\u8166 \u8001\u5e2b, IT freelance \u548c programming expert. \u8b93\u5927\u5bb6\u65b9\u4fbf\u5730\u5c31\u80fd\u627e\u5230\u5408\u9069\u7684\u96fb\u8166\u88dc\u7fd2, \u96fb\u8166\u73ed, \u5bb6\u6559, \u79c1\u4eba\u8001\u5e2b.  <br>\r\n\r\nWe are a education and information platform which you can find a IT private tutorial teacher or freelance. <br>\r\n\r\nAlso we provide different information about information technology, Computer, programming, mobile, Android, apple, game, movie, anime, animation\u2026 \r\n<\/p>\n<p><br>(2) ITSec<br> <\/p><a href=https:\/\/itsec.vip><img src=http:\/\/gamefootballmobileanimeiphone.com\/wp-content\/uploads\/2023\/09\/ITSec-Main-Promotion-Image.png alt= https:\/\/itsec.vip\/\r\nSecure Your Computers from Cyber Threats and mitigate risks with professional services to defend Hackers.  \r\nITSec provide IT Security and Compliance Services, including IT Compliance Services, Risk Assessment, IT Audit, Security Assessment and Audit, ISO 27001 Consulting and Certification, GDPR Compliance Services, Privacy Impact Assessment (PIA), Penetration test, Ethical Hacking, Vulnerabilities scan, IT Consulting, Data Privacy Consulting, Data Protection Services, Information Security Consulting, Cyber Security Consulting, Network Security Audit, Security Awareness Training.\/><\/a> \r\n<br><br> \r\n<p><a href=https:\/\/itsec.vip>www.ITSec.vip<\/a> <br> <br> \r\n<p><a href=https:\/\/sraa.com.hk>www.Sraa.com.hk<\/a> <br> <br> \r\n<p><a href=https:\/\/itsec.hk>www.ITSec.hk<\/a> <br> <br> \r\n<p><a href=https:\/\/penetrationtest.hk>www.Penetrationtest.hk<\/a> <br> <br> \r\n<p><a href=https:\/\/itseceu.uk>www.ITSeceu.uk<\/a> <br> <br> \r\nSecure Your Computers from Cyber Threats and mitigate risks with professional services to defend Hackers. <br><br>\r\nITSec provide IT Security and Compliance Services, including IT Compliance Services, Risk Assessment, IT Audit, Security Assessment and Audit, ISO 27001 Consulting and Certification, GDPR Compliance Services, Privacy Impact Assessment (PIA), Penetration test, Ethical Hacking, Vulnerabilities scan, IT Consulting, Data Privacy Consulting, Data Protection Services, Information Security Consulting, Cyber Security Consulting, Network Security Audit, Security Awareness Training. \r\n<br><br>Contact us right away. <br><br>Email (Prefer using email to contact us): <br>SalesExecutive@ITSec.vip<\/p>","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.baeldung.com\/wp-content\/uploads\/2021\/09\/Java-8-Featured-1024x536.png\" class=\"webfeedsFeaturedVisual wp-post-image\" alt=\"\"><\/p>\n<p>Explore several String composition techniques and understand the idea behind String interpolation.<\/p>\n<div><a title=\"Like on Facebook\" href=\"https:\/\/feeds.feedblitz.com\/_\/28\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/fblike20.png\"><\/a>\u00a0<a title=\"Pin it!\" href=\"https:\/\/feeds.feedblitz.com\/_\/29\/796683116\/baeldung,https%3A%2F%2Fwww.baeldung.com%2Fwp-content%2Fuploads%2F2021%2F09%2FJava-8-Featured-1024x536.png\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/pinterest20.png\"><\/a>\u00a0<a title=\"Tweet This\" href=\"https:\/\/feeds.feedblitz.com\/_\/24\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/twitter20.png\"><\/a>\u00a0<a title=\"Subscribe by email\" href=\"https:\/\/feeds.feedblitz.com\/_\/19\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/email20.png\"><\/a>\u00a0<a title=\"Subscribe by RSS\" href=\"https:\/\/feeds.feedblitz.com\/_\/20\/796683116\/baeldung\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/rss20.png\"><\/a>\u00a0<a rel=\"NOFOLLOW\" title=\"View Comments\" href=\"https:\/\/www.baeldung.com\/java-21-string-templates#respond\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/comments20.png\"><\/a>\u00a0<a title=\"Follow Comments via RSS\" href=\"https:\/\/www.baeldung.com\/java-21-string-templates\/feed\"><img decoding=\"async\" height=\"20\" src=\"https:\/\/assets.feedblitz.com\/i\/commentsrss20.png\"><\/a>\u00a0<\/div>\n","protected":false},"author":258,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[22],"tags":[61,122,127,129,124,128,125,132,131,133,126,130,123,66,94,88,97,56,64,65,60,112,40,75,95,104,33,120,105,101,98,115,30,29,41,86,70,69,68,72,71,26,118,108,87,46,55,48,52,54,51,50,83,62,58,57,2516,2515,109,35,59,63,85,79,82,96,80,27,81,114,44,42,43,45,38,39,110,117,100,111,116,73,89,90,92,91,93,84,78,37,102,34,36,77,67,74,99,113,119,28,2517,121,32,47,49,53,103,31,76],"class_list":["post-5690","post","type-post","status-publish","format-standard","hentry","category-mobile","tag-airpods","tag-anime","tag-anime-characters","tag-anime-cosplay","tag-anime-edits","tag-anime-merchandise","tag-anime-movies","tag-anime-news","tag-anime-recommendations","tag-anime-reviews","tag-anime-series","tag-anime-streaming","tag-animes","tag-app-store","tag-app-store-samsung","tag-appgallery","tag-appgallery-oneplus","tag-apple","tag-apple-music","tag-apple-tv","tag-apple-watch","tag-bbc-sport","tag-best-mobile-games","tag-bixby","tag-bixby-xiaomi","tag-champions-league","tag-cyberpunk","tag-cyberpunk-2077","tag-fantasy-football","tag-fifa","tag-football","tag-formula-1","tag-fortnite","tag-free-fire","tag-free-mobile-games","tag-freebuds-pro","tag-galaxy-a52","tag-galaxy-note-20","tag-galaxy-s21","tag-galaxy-watch-4","tag-galaxy-z-fold-3","tag-game","tag-games","tag-golf","tag-harmonyos","tag-how-to-backup-iphone","tag-how-to-factory-reset-iphone","tag-how-to-reset-iphone","tag-how-to-restore-iphone","tag-how-to-unlock-iphone","tag-how-to-unlock-iphone-5","tag-how-to-unlock-iphone-6","tag-huawei","tag-ios","tag-ipad","tag-iphone","tag-java-21","tag-java-string","tag-live-soccer","tag-lol","tag-macbook","tag-macos","tag-mate-40-pro","tag-mi-11-lite","tag-mi-home-security-camera-basic-1080p","tag-mi-home-security-camera-basic-1080p-huawei","tag-mi-smart-band-6","tag-minecraft","tag-miui","tag-mlb-scores","tag-mobile-game-design","tag-mobile-game-development","tag-mobile-game-marketing","tag-mobile-game-monetization","tag-mobile-games","tag-mobile-gaming","tag-nba-scores","tag-nba-standings","tag-nfl","tag-nfl-scores","tag-nhl-scores","tag-one-ui","tag-oneplus","tag-oneplus-9-pro","tag-oneplus-buds-pro","tag-oneplus-nord-ce-5g","tag-oxygenos","tag-p40-pro-plus","tag-poco-x3-pro","tag-pokemon","tag-premier-league","tag-pubg","tag-pubg-mobile","tag-redmi-note-10-pro","tag-samsung","tag-samsung-pay","tag-soccer","tag-sports","tag-steam","tag-steeam","tag-stringbuilder","tag-top-10-anime","tag-valorant","tag-when-do-the-iphone-7-come-out","tag-when-does-the-iphone-7-come-out","tag-when-is-the-iphone-7-coming-out","tag-world-cup","tag-xbox-series-x","tag-xiaomi"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/posts\/5690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/users\/258"}],"replies":[{"embeddable":true,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/comments?post=5690"}],"version-history":[{"count":2,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/posts\/5690\/revisions"}],"predecessor-version":[{"id":5703,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/posts\/5690\/revisions\/5703"}],"wp:attachment":[{"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/media?parent=5690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/categories?post=5690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gamefootballmobileanimeiphone.com\/index.php\/wp-json\/wp\/v2\/tags?post=5690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}