如果有人用 mu子收集,那么,我是否能够复制脚ack,以便我能够用手套,在不改变原来的 st子的情况下分析其内容? 例如,我有一 st,其代码如下:
import scala.collection.mutable.Stack
var stack1 = new Stack[Int]
/** Code that pushes integers on stack1*/
var stackCopy = stack1
while (!stackCopy.isEmpty) {
println(stackCopy.pop)
}
I want to use a while loop to print all elements in stack1. But when I make a copy and pop off that copy, the original stack (i.e. stack1) is also altered. I want to preserve the original stack, so how can I just get the contents, not the address?