Java
Text Blocks
Java 15+ multi-line strings.
By EZ4Code Team
text-blockstring
Code
// Text block
String json = """
{
"name": "Alice",
"age": 30,
"city": "Beijing"
}
""";
String sql = """
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.active = true
GROUP BY u.name
HAVING COUNT(o.id) > 0
ORDER BY order_count DESC
""";
// Escaping and formatting
String template = """
Hello, %s!
Your balance is $%.2f
""".formatted("Alice", 1234.5678);Explanation
Text blocks define multi-line strings with triple quotes, preserving format and supporting escapes.
More Java Snippets
String Operations and StringBuilder
Manipulate strings with split, join, substring, and StringBuilder in Java.
Stream API
Process collections using the Stream API.
Lambda Expressions
Simplify code with Lambda expressions.
Optional
Handle null values elegantly.
Collection Operations
Common operations on List, Set, and Map.
Exception Handling
try-catch-finally and custom exceptions.