-2

What is the difference of these two snippets of code? And how to decide which one to use?

var array = arrayOf(1,2,3,4,5)

and

var list = listOf(1,2,3,4,5)

With both codes I could access it by its index like this

println(array[0]) // Outputs 1  
println(list[0]) // Outputs 1 
0

1 Answer 1

0

The difference is the datatype:

var array = arrayOf(1,2,3,4,5)  --> class kotlin.Array
var list = listOf(1,2,3,4,5)    --> class java.util.Arrays$ArrayList

You have to decide which data type fits your needs the best.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.