Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 2, 2019 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/1289fbbc3a4a50283bda35384289c0e9 to your computer and use it in GitHub Desktop.
Save parzibyte/1289fbbc3a4a50283bda35384289c0e9 to your computer and use it in GitHub Desktop.
fun main() {
// by parzibyte
// Definir un arreglo con arrayOf
val nombres = arrayOf("Luis", "María José", "Fernando")
println(nombres[1]) // María José
for (nombre in nombres){
println(nombre)
}
for (indice in nombres.indices){
println("En el índice ${indice} tenemos a ${nombres[indice]}")
}
// Declararlo con su longitud y una función de init
val arregloDeEnteros = Array(5, { indice -> indice + 1})
// Se puede modificar como cualquier arreglo
arregloDeEnteros[2] = 500
for (numero in arregloDeEnteros){
println(numero)
}
// Acceder a longitud
val longitud = arregloDeEnteros.size
println("La longitud del arreglo es $longitud")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment