Java 13 Tutorial
Java Other Versions Tutorials
Java 13 Useful Resources
Selected Reading
- Java 13 - ZGC Enhancements
- Java 13 - Dynamic CDS Archive
- Java 13 - Miscellaneous Changes
- Java 13 - Socket API Reimplementation
- Java 13 - Text Block Methods
- Java 13 - Text Blocks
- Java 13 - Switch Expressions
- Java 13 - Environment Setup
- Java 13 - Overview
- Java 13 - Home
Java Other Versions Tutorials
Java 13 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 13 - Text Blocks
Java 13 - Text Blocks
Java 13 introduces text blocks to handle multipne strings pke JSON/XML/HTML etc. It is a preview feature.
Text Block allows to write multipne strings easily without using .
Text Block string have same methods as string pke contains(), indexOf() and length() functions.
Example
Consider the following example −
ApiTester.java
pubpc class APITester { pubpc static void main(String[] args) { String stringJSON = "{ " + ""Name" : "Mahesh", " + ""RollNO" : "32" " + "}"; System.out.println(stringJSON); String textBlockJSON = """ { "name" : "Mahesh", "RollNO" : "32" } """; System.out.println(textBlockJSON); System.out.println("Contains: " + textBlockJSON.contains("Mahesh")); System.out.println("indexOf: " + textBlockJSON.indexOf("Mahesh")); System.out.println("Length: " + textBlockJSON.length()); } }
Compile and Run the program
$javac -Xpnt:preview --enable-preview -source 13 APITester.java $java --enable-preview APITester
Output
{ "Name" : "Mahesh", "RollNO" : "32" } { "name" : "Mahesh", "RollNO" : "32" } Contains: true indexOf: 15 Length: 45Advertisements