How do i make a user enter input to eliminate an element from stack A to stack B? For example, i hv 3 stacks: st, st2, st3. I want to let user to choose which stack they want to eliminate an element from and to which stack they want to add that element to. Let say user enter "From: 0" and "To: 1" which means the program hv to remove an element from st and add the removed element to st2. I know one of the ways is somehow like this: 'st2.push(st.pop())' in which will eliminate element from st stack and add to st2 stack. But thats now what i want. I want it to be like this: st(i).push(st(i).pop()) in which "i" indicates the stack position the user entered suppose.
And why does calling hello[0] returns 'bye' only rather than the whole st stack?
package stack;
import java.util.*;
public class StackDemo {
public static void main(String args[]) {
// creating stack
Stack st = new Stack();
Stack st2 = new Stack();
Stack st3 = new Stack();
// populating stack
st.push("Java");
st.push("Source");
st.push("code");
st2.push("hello");
st3.push("bye");
String[] hello = new String[3];
st.toArray(hello);
st2.toArray(hello);
st3.toArray(hello);
System.out.println("hello: ");
System.out.println("Get 0: " + hello[0]);
}
}