use variable inside triple quote java

Any idea if it is possible to use variable inside triple quote ?

something like this:

private String myVariable = "test";

private String myVariable2 = 
  """
    value: ${myVariable}
  """ 

>Solution :

You can call formatted directly on the multiline String:

String a = """
        value: %s
        """.formatted(123);

This might be a little more readable and/or elegant than String.format(multiLineLiteral, value).

Leave a Reply