indexOf

expect open override 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')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e')) 
   //sampleEnd
}
actual open override 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')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e')) 
   //sampleEnd
}
actual open override 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')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e')) 
   //sampleEnd
}
actual open override 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')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e')) 
   //sampleEnd
}
actual open override 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')
assertEquals(0, list.indexOf('a'))
assertEquals(1, list.indexOf('b'))
assertEquals(-1, list.indexOf('e')) 
   //sampleEnd
}