Last active
October 30, 2019 10:25
-
-
Save mloza/d21b5af3580f1317ea79f81790659d3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextBlocksConcatenation { | |
public static void main(String[] args) { | |
String title = "Hello title"; | |
String header = "Hello header"; | |
System.out.println(""" | |
<html> | |
<head> | |
<title>""" + title + """ | |
</title> | |
</head> | |
<body> | |
<h1>""" + header + """ | |
</h1> | |
</body> | |
</html> | |
"""); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.8.0</version> | |
<configuration> | |
<release>13</release> | |
<compilerArgs>--enable-preview</compilerArgs> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pl.mloza; | |
public class TextBlocksFormatting { | |
private static String indentation = """ | |
<html> | |
<head> | |
<title>%s</title> | |
</head> | |
<body> | |
<h1>%s</h1> | |
</body> | |
</html> | |
"""; | |
public static void main(String[] args) { | |
System.out.println(indentation.formatted("Hello title", "Hello header")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextBlocksIndentation { | |
// #1 | |
private static String indentation = """ | |
<html> | |
<head> | |
<title>Hello world!</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
</body> | |
</html> | |
"""; | |
// #2 | |
private static String indentationTwo = """ | |
<html> | |
<head> | |
<title>Hello world!</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
</body> | |
</html> | |
"""; | |
public static void main(String[] args) { | |
System.out.println(indentation); | |
System.out.println(indentationTwo); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextBlocksInvalid { | |
// #1 | |
private static String invalidOne = """"""; | |
// #2 | |
private static String invalidTwo = """ """; | |
// #3 | |
private static String invalidThree = """ | |
"; | |
// #4 | |
private static String invalidFour = """ | |
asd \ asd | |
""""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pl.mloza; | |
public class TextBlocks { | |
private static String classic = " <html>\n" + | |
" <head>\n" + | |
" <title>Hello world!</title>\n" + | |
" </head>\n" + | |
" <body>\n" + | |
" <h1>Hello World</h1>\n" + | |
" </body>\n" + | |
" </html>"; | |
private static String block = """ | |
<html> | |
<head> | |
<title>Hello world!</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
</body> | |
</html> | |
"""; | |
public static void main(String[] args) { | |
System.out.println(classic); | |
System.out.println(block); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextBlocksTwo { | |
// #1 | |
private static String noLineEnding = """ | |
<html> | |
<head> | |
<title>Hello world!</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
</body> | |
</html>"""; | |
// #2 | |
private static String block = """ | |
"We can put here quotes but slashes needs to be escaped \\" | |
Comments are not working here # // /* xxx */ | |
Triple quotes needs to be escaped \""" | |
"""; | |
// #3 | |
private static String emptyString = """ | |
"""; | |
// #4 | |
private static String blockConcatenation = block + noLineEnding; | |
// #5 | |
private static String escapeSequences = """ | |
First line \n Second line | |
"""; | |
public static void main(String[] args) { | |
System.out.println(noLineEnding); | |
System.out.println(block); | |
System.out.println("Empty string: " + emptyString); | |
System.out.println(blockConcatenation); | |
System.out.println(escapeSequences); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment