indexOf
Returns the index of the first occurrence of the specified element in the list, or -1
if the specified element is not contained in the list.
For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.
Since Kotlin
1.0Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c', 'a')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e'))
//sampleEnd
}
Returns the index of the first occurrence of the specified element in the list, or -1
if the specified element is not contained in the list.
For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.
Since Kotlin
1.1Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c', 'a')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e'))
//sampleEnd
}
Returns the index of the first occurrence of the specified element in the list, or -1
if the specified element is not contained in the list.
For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c', 'a')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e'))
//sampleEnd
}
Returns the index of the first occurrence of the specified element in the list, or -1
if the specified element is not contained in the list.
For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c', 'a')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e'))
//sampleEnd
}
Returns the index of the first occurrence of the specified element in the list, or -1
if the specified element is not contained in the list.
For lists containing more than Int.MAX_VALUE elements, a result of this function is unspecified.
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = listOf('a', 'b', 'c', 'a')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e'))
//sampleEnd
}