.isEmpty
or .nonEmpty
when checking for empty String
s SC-R1022The String
type in Scala implements methods such as .isEmpty
and .nonEmpty
that you can use to check if a string is empty or not. While you can also use the comparison operators against an empty string, it is generally not considered as the right approach and is recommended that you use the said builtin methods.
val lang = " Scala "
if (lang != "" && lang.trim != "") {
// ...
}
val lang = " Scala "
if (lang.nonEmpty && lang.trim.nonEmpty) {
// ...
}