Java 15 Tutorial
Java Other Versions Tutorials
Java 15 Useful Resources
Selected Reading
- Java 15 - Deprecation & Removals
- Java 15 - Other Enhancements
- Java 15 - Deprecation & Removals
- Java 15 - Other Changes
- Java 15 - Garbage Collectors
- Java 15 - Hidden Classes
- Java 15 - record & Sealed Classes
- Java 15 - record
- Java 15 - Text Blocks
- Java 15 - Pattern for instanceOf
- Java 15 - Sealed Classes
- Java 15 - Environment Setup
- Java 15 - Overview
- Java 15 - Home
Java Other Versions Tutorials
- Java 14 Tutorial
- Java 13 Tutorial
- Java 12 Tutorial
- Java 11 Tutorial
- Java 10 Tutorial
- Java 9 Tutorial
- Java 8 Tutorial
- Java Tutorial
Java 15 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 15 - Text Blocks
Java 15 - Text Blocks
Java 13 introduces text blocks to handle multipne strings pke JSON/XML/HTML etc as is a preview feature. With Java 14, we ve second preview of Text Blocks. Now Text Block is no more a preview feature and is a part of standard offering.
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 APITester.java $java APITester
Output
{ "Name" : "Mahesh","RollNO" : "32" } { "name" : "Mahesh", "RollNO" : "32" } Contains: true indexOf: 15 Length: 45Advertisements