Click the tabs below to switch between languages. Only one code block should be visible at a time.
public static String processText(String text) {
if (text == null || text.isBlank()) {
return "";
}
return text.lines()
.map(String::strip)
.filter(line -> !line.isBlank())
.collect(Collectors.joining("\n"));
}
def processText(text: String): String =
Option(text)
.filter(_.trim.nonEmpty)
.map(_.linesIterator
.map(_.strip)
.filter(_.nonEmpty)
.mkString("\n"))
.getOrElse("")
fun processText(text: String?): String {
if (text.isNullOrBlank()) return ""
return text.lines()
.map { it.trim() }
.filter { it.isNotBlank() }
.joinToString("\n")
}
String json = """
{
"name": "%s",
"email": "%s"
}
""".formatted(name, email);
val json = s"""{
| "name": "$name",
| "email": "$email"
|}""".stripMargin
val json = """
{
"name": "$name",
"email": "$email"
}
""".trimIndent()