Most asked top Interview Questions and Answers | Online Test | Mock Test
Education platform for interview prep, online tests, tutorials, and live practice

Build skills with focused learning paths, mock tests, and interview-ready content.

WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.

Search the library
Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is String.stripIndent() in Java 15?
Answer:

Suppose we have a multi-line string where each line is intended and has some trailing spaces, such as the following. We print each line, bounded by two vertical bars.

String html = """
<html> s
<body> s
<h1>Hello!</h1>
</body> s
</html> s
""";

html.lines()
.map(line -> "|" + line + "|")
.forEachOrdered(System.out::println);
Code language: Java (java)

As you learned in the first chapter, the alignment of a text block is based on the closing quotation marks. The output, therefore, looks like this:

|  <html>     |
| <body> |
| <h1>Hello!</h1>|
| </body> |
| </html> |

Using the stripIndent() method, we can remove the indentation and trailing spaces:

html.stripIndent()
.lines()
.map(line -> "|" + line + "|")
.forEachOrdered(System.out::println);

The output is now:

|<html>|
| <body>|
| <h1>Hello!</h1>|
| </body>|
|</html>|

Save For Revision

Bookmark this item, mark it difficult, or place it in a revision set.

Open My Learning Library
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook