My question is simple. If I have a data structure like a stack in java and add some elements, then I create other stack and equals to first stack using = operator (Example 1) instead empty the first one using while loop (Example 2). If i try to use the second stack in other scope, Can I lost the data if first stack is empty?
Stack<String> stack=new Stack<>();
Stack<String> stack_aux=new Stack<>();
stack.push("Hola");
stack.push("Mundo");
stack.push("in Java");
Example 1
stack_aux=stack;
Example 2
while(!stack.isEmpty()){
stack_aux.push(stack.pop());
}