elementAt

expect fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)
assertPrints(list.elementAt(0), "1")
assertPrints(list.elementAt(2), "3")
assertFailsWith<IndexOutOfBoundsException> { list.elementAt(3) }

val emptyList = emptyList<Int>()
assertFailsWith<IndexOutOfBoundsException> { emptyList.elementAt(0) } 
   //sampleEnd
}
actual inline fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)
assertPrints(list.elementAt(0), "1")
assertPrints(list.elementAt(2), "3")
assertFailsWith<IndexOutOfBoundsException> { list.elementAt(3) }

val emptyList = emptyList<Int>()
assertFailsWith<IndexOutOfBoundsException> { emptyList.elementAt(0) } 
   //sampleEnd
}
actual fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)
assertPrints(list.elementAt(0), "1")
assertPrints(list.elementAt(2), "3")
assertFailsWith<IndexOutOfBoundsException> { list.elementAt(3) }

val emptyList = emptyList<Int>()
assertFailsWith<IndexOutOfBoundsException> { emptyList.elementAt(0) } 
   //sampleEnd
}
actual inline fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val list = listOf(1, 2, 3)
assertPrints(list.elementAt(0), "1")
assertPrints(list.elementAt(2), "3")
assertFailsWith<IndexOutOfBoundsException> { list.elementAt(3) }

val emptyList = emptyList<Int>()
assertFailsWith<IndexOutOfBoundsException> { emptyList.elementAt(0) } 
   //sampleEnd
}