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...

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...

Hello,

Please check here : http://java.sun.com/javase/6/docs/api/java/util/Stack.html

Hope this will clear your confusion :)

Regards,

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"

thank you very much for the help guyzz...,,now it's clear for me....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.