// Basic text block
String text = """
This is a
multi-line
string
""";
// SQL query
String query = """
SELECT u.id, u.name, u.email
FROM users u
WHERE u.status = 'ACTIVE'
AND u.created_at > '2024-01-01'
ORDER BY u.name
""";
// JSON string
String json = """
{
"name": "Alice",
"age": 25,
"hobbies": ["reading", "coding"]
}
""";
// HTML template
String html = """
<div class="container">
<h1>Welcome</h1>
<p>This is a paragraph</p>
</div>
""";
// XML
String xml = """
<person>
<name>John</name>
<age>30</age>
</person>
""";
// Using with String methods
String formatted = """
Hello %s,
Welcome to %s!
""".formatted("Alice", "Java");
// Text block with escape sequences
String withEscapes = """
Normal text
Text with \"quotes\"
Text with \\backslash
""";
// Code template
String codeTemplate = """
public class %s {
private String %s;
public %s(String %s) {
this.%s = %s;
}
}
""".formatted("Person", "name", "Person", "name", "name", "name");
// Multi-line message
String message = """
Error occurred:
- File not found
- Permission denied
Please check the file path.
""";