var l=Array<ArrayList<Int>()>(5){};
I tried the above code but, it gave me a compile time error. What is the correct way to achieve this?.
var l=Array<ArrayList<Int>()>(5){};
I tried the above code but, it gave me a compile time error. What is the correct way to achieve this?.
This is the full syntax to do this:
val l: Array<ArrayList<Int>> = Array<ArrayList<Int>>(5) { ArrayList<Int>() }
You can simplify this in a couple of ways, for example you can leave out the type on the left:
val l = Array<ArrayList<Int>>(5) { ArrayList<Int>() }
And then you can also leave out some more of the types, either of these ways:
val l = Array<ArrayList<Int>>(5) { ArrayList() }
val l = Array(5) { ArrayList<Int>() }