Another question: this code snipped: ``` fun doStu...
# announcements
a
Another question: this code snipped:
Copy code
fun doStuff(input:String) {
   val split = input.split("foo", 0)
}
will not compile, but this one:
Copy code
fun doStuff(input:String) {
   val split = java.lang.String(input).split("foo", 0)
}
will be OK. Is it supposed behaviour (in other words, is it a bug or is it a feature)?
a
thats expected behaviour, because
kotlin.String.split
is not the same as
java.lang.String.split
, they have different parameters
i
You can use
val split = input.split("foo", limit = 0)
. Also mind that: 1)
limit = 0
is the default value for
limit
, so there's no need to specify it explicitly. 2)
split("foo")
treats
foo
delimiter as a literal rather than a regular expression.
a
@ilya.gorbunov Yes, I saw the Kotlin version of
split
, and I found that behaviour of
limit
is different with Java. Java doc says that
If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
, however Kotlin implementation keeps trailing empty strings