Q:

Split directory from string in Kotlin

I guys,
I'm trying to split the directory of string like this:
val pwd = "travel/holiday/"
val listOfDirectory = pwd.split("/".toRegex())

output: "travel","holiday",""

Why is created a blank space in the last position? Also, How can I remove that?

A:

The empty string is there because you've got "/" after "holiday".
You can skip empty elements using 'filter' extension function like this:
val listOfDirectory = pwd.split("/").filter { it.isNotEmpty() }

