How would you guys make a list of string be joined...
# codereview
d
How would you guys make a list of string be joined but with the condition that if a String is null or blank it won't be included in the resulting string? Is there a function that does it? I couldn't find such function so I created this extension
Copy code
fun String.Companion.joinIfNotNullOrBlank(vararg params: String?, separator: String = ", "): String =
    params.filter { !it.isNullOrBlank() }.joinToString(separator)
l
Seems good to me. I would consider
filterNot
and making the function an extension of
Collection<String>
, but it might depend on how you plan to call it
👍 2