dan09/05/2020, 9:41 AM
val res : Array<Int> = emptyArray() res.plus(1) println(res.size)
Paula Muldoon09/05/2020, 9:45 AM
dan09/05/2020, 9:46 AM
Paula Muldoon09/05/2020, 9:47 AM
function seems to create a new empty array (hence why it’s not throwing an error).
, which is immutable but not fixed length so you can add more elements to it. If you really need mutable, there is
dan09/05/2020, 9:53 AM
in my use case.
Paula Muldoon09/05/2020, 9:59 AM
(as long as you obey the array type).
myArray = 2
are immutable but you can create a new list by using
, which would generally be safer / preferable as you aren’t modifying the original list.
val newList = oldList.plus(1)
are less safe (something else could be modifying your list at the same time) so it’s generally preferable to use an immutable list.
dan09/05/2020, 10:05 AM
Ruckus09/05/2020, 3:32 PM
Val res = mutableListOf<Int>() res += 1 println(res.size) // 1