-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiLineStringExample.java
More file actions
59 lines (51 loc) · 1.33 KB
/
Copy pathMultiLineStringExample.java
File metadata and controls
59 lines (51 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Java13;
//multiline string is a string that spans multiple lines of source code
//multiline string is enclosed in three double quotes (""")
//multiline string is useful for writing HTML, SQL, JSON, etc.
//multiline string is a preview feature in Java 13
//multiline string is a standard feature in Java 15
public class MultiLineStringExample {
public static void main(String[] args) {
//Example 1: Multiline String
String html = """
<html>
<body>
<p>Hello, World</p>
</body>
</html>
""";
System.out.println(html);
//Example 2: Multiline String
String query = """
SELECT *
FROM users
WHERE id = 1
""";
System.out.println(query);
//Example 3: Multiline String with expressions
String name = "John";
String message = """
Hello, %s
How are you?
""".formatted(name);
System.out.println(message);
//multiline string before java 13
String htmlBeforeJava13 = "<html>\n" +
" <body>\n" +
" <p>Hello, World</p>\n" +
" </body>\n" +
"</html>";
}
}
/*Output:
<html>
<body>
<p>Hello, World</p>
</body>
</html>
SELECT *
FROM users
WHERE id = 1
Hello, John
How are you?
*/