I want to implement a function that will return the indexes of the substrings in the specified string. For now i did it in Java-style:
public fun String?.indexesOf(substr: String, ignoreCase: Boolean = true): List<Int> {
var list = mutableListOf<Int>()
if (substr.isNullOrBlank()) return list
var count = 0;
this?.split(substr, ignoreCase = ignoreCase)?.forEach {
count += it.length
list.add(count)
count += substr.length
}
list.remove(list.get(list.size-1))
return list
}
But I don't think this is a kotlin-way solution. Its most looks like typical java program but written in kotlin. How can this be implemented more elegantly using kotlin?
list.dropLast(1)instead oflist.remove(list.get(list.size-1))