1

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.