Reputation: 13
Is there a way to search through a string array and return its index if it is found. Of course I can just iterate through the array and perform the search myself. But I am wondering if there is a more efficient way of doing it. Kotlin has the "contains" method but that returns a boolean. I want the index position instead.
Upvotes: 1
Views: 1242
Reputation: 2233
If you need to find specific string's index, then you should use indexOf()
method. E.g.
val index = listOf("a","b","c").indexOf("a")
It will return -1 if the string is not found though.
Upvotes: 3