Skip to content

Latest commit

 

History

History
52 lines (32 loc) · 987 Bytes

Arrays in Kotlin.md

File metadata and controls

52 lines (32 loc) · 987 Bytes
date updated date created date modified
2021-11-02 20:24
Friday, November 19th 2021, 2:00:25 pm
Tuesday, November 2nd 2021, 8:26:16 pm

Topic: #kotlin

Tags: #review #pn_2_1

Links: [[Type in Kotlin]]

Date Created: 02-11-21


Arrays in Kotlin

Arrays in Kotlin in Few Words

Arrays in Kotlin in Details

[[Arrays in Kotlin]] are invariant, this means that the [[Type]] cannot be changed.

If we want to have dynamic array [[Type|types]] then we should use a [[Generics]], more precisely [[Generics in Kotlin#Type Projections|Type Projections]].

Build an Array

With a [[Constructor]]

val tab = Array<Type>(size) { values}

With a [[Factory]]1

val tab = arrayOf(val1, val2,  ...)

Access An Item

tab.get(indexOfDesiredItem)
tab[indexOfDesiredItem]

Primitive Type Arrays

References

Footnotes

  1. note that this link might talk about factory from another language which might not be the same in Kotlin