java remove empty lines from string

102

java remove empty lines from string -

String text = "line 1\n\nline 3\n\n\nline 5";
String adjusted = text.replaceAll("(?m)^[ \t]*\r?\n", "");
// ...

Comments

Submit
0 Comments