[SOLVED] I have a string, something like "Test;Tes...
# android
l
[SOLVED] I have a string, something like "Test;Test1;;;;;". Applying
Copy code
myString
    .map { it.split(";") }
gives me a
List<List<String>>
where the last items are empty strings because
split
interperets ";" as empty string ->
""
. I would like to have
null
instead of
""
. How can I achieve this? Output should be
List<List<String?>>
a
.map { if(it != "") it else null }
l
it
is a List<String>, that does not work
I could do:
Copy code
.map { it.split(";") }
.flatten()
.map { it.ifBlank { null } }
but then I don't know how to get it back to
List<List<String?>>
a
applying map on the string splits it into a list where every character is one item. is that what you are trying to do?
l
Thanks @ade, you enlighten me. This works:
Copy code
.map { it.split(";").map { item -> item.ifBlank { null } } }
👍 1