Snippet: Remove blank lines from text
text.replaceAll("(?m)(^\\s*$\\r?\\n)+", "")
Or via Pattern
objects:
import java.util.regex.Pattern
Pattern
.compile("(^\\s*$\\r?\\n)+", Pattern.MULTILINE)
.matcher(text)
.replaceAll("")
| Written by Alexandru Nedelcu