Yes, it's this line:
list = temp;
All that does is copy the temp
reference to the list
reference. Now, both list
and temp
refer to your local list originally referred to by temp
.
You'll want to add the contents of temp
back to list
instead.
list.addAll(temp);