Variables updating in lists when they shouldn't

I’m brand new to kotlin, like I just started today, and I’m currently coding a function that will take a list and make a list of lists using it like this. [1,2,3] → [[1],[1,2],[1,2,3]]. However, it’s acting weird and I don’t know how to fix it. I’m getting the output [[1,2,3],[1,2,3],[1,2,3]]. What’s happening is that I’m using the same variable to insert things in, and when that variable updates so does all the lists inside the list of lists. So on the first loop the list of lists has [[1]], and after the second it has [[1,2],[1,2]]

here is my code
fun subLists(list:List?) :List<List>?{
if(list == null) {
return null
}
var buildingList = mutableListOf()
var listOfLists = mutableListOf<List>()
if(list.isNotEmpty()) {
var count = 0
while(count < list.size) {
buildingList.add(list[count])
listOfLists.add(copyList(buildingList))
println(“listlist” + listOfLists)
count++
}
}
return listOfLists
}
inputing [2, 3, 5, 7, 11] I get the output of
listlist[[2]]
listlist[[2, 3], [2, 3]]
listlist[[2, 3, 5], [2, 3, 5], [2, 3, 5]]
listlist[[2, 3, 5, 7], [2, 3, 5, 7], [2, 3, 5, 7], [2, 3, 5, 7]]
listlist[[2, 3, 5, 7, 11], [2, 3, 5, 7, 11], [2, 3, 5, 7, 11], [2, 3, 5, 7, 11], [2, 3, 5, 7, 11]]

is there an easy way to prevent that from happening?

Thank You

Ok, I figured it out, so you can’t insert a list, you have to insert the individual values. To do that you first need to make listOfList a mutable list of mutable lists that way you can code listOfList[i].add(number)