indexOf

expect abstract fun indexOf(element: E): Int(source)

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.0

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}
actual abstract fun indexOf(element: E): Int(source)

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.1

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}
actual abstract fun indexOf(element: E): Int(source)

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.0

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}
actual abstract fun indexOf(element: E): Int(source)

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.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}
actual abstract fun indexOf(element: E): Int(source)

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.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}
actual abstract fun indexOf(element: E): Int(source)

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.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = listOf('a', 'b', 'c', 'a')
println(list.indexOf('a')) // 0
println(list.indexOf('b')) // 1
println(list.indexOf('e')) // -1 
   //sampleEnd
}