hello guy,,can you really help me understand more about "stack" in java??
i am still confused about stack.push or stack.pop.....can you help me understand it more??..thank you again...

The concept of stack is not unique in java. It applies not only in the programming world but everywhere, so I will explain the basic concept.

When you put items in a stack you place each one of them after the other. But when you try to take these items from the stack you can only take the last one you entered not the first. If you have a stack of plates you put one on top of the other, but you cannot take the one at the bottom (the one you put first), you must take the one at the top, which was the one you placed last.

In java, you can store objects in a stack the same way. Assume you call push several times:

push("AAA")
push("BBB")
push("CCC")

when you call the pop command you will get the value: "CCC". If you call pop again you will get the "BBB". You will be getting the items in the opposite order you put them


Now if you use an ArrayList and do this:

add("AAA")
add("BBB")
add("CCC")

And then try to get the values with method get(int i) , you will have the values in the order placed in them:
"AAA"
"BBB"
"CCC"

This question has already been answered. Start a new discussion instead.