Remove blank lines from text in Java/Scala

| comments

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