Text Blocks with Format Specifiers

 Text Blocks with Format Specifiers


Java 16 introduced an enhancement to text blocks that allows for the inclusion of format specifiers within the text block. This feature allows for the easy formatting of text within the text block.


Example:



String message = """

                  Dear %s,

                  

                  Thank you for your recent order.

                  Your order number is %d.

                  

                  Regards,

                  The Store

                  """;

String formatted = String.format(message, "John", 12345);

System.out.println(formatted);

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...