Different types of data in the same Array?

1

It is possible to have more than one type of data in an arrayOf, a ListOf or an arrayListOf Or is it not possible to have Int and String data, for example, in the same Array?

    
asked by Daniel 14.10.2018 в 07:05
source

2 answers

1

If possible, you could create an Any List and instantiate it as follows:

val myList = mutableListOf<Any>()

And you would add objects to it in the following way.

myList.add("string")
myList.add(MyObject(null, null))

Try it, and let me know. Greetings.

    
answered by 14.10.2018 в 07:35
0

Yes you can, you must use arrayOf () to generate an array with mixed values :)

val myArray = arrayOf(4, 5, 7, "3", "Chike", false).

Doc. link

    
answered by 14.10.2018 в 07:10