-2

I have a string:

String str = "    line0\n" +
                "line1\n" +
                "line2    line0\n" +
                "line3\n" +
                "line4   \n"

How can I get the following script:

String formatedStr = "line0\n" +
                    "line1\n" +
                    "line2    line0\n" +
                    "line3\n" +
                    "line4"
Alex
  • 3
  • 2

1 Answers1

-1

You can do it as follows

String formattedStr = str.trim();

Refer java-string-trim-method-example for more details.