read last value from stack (java) -


i created stack store values follows. need read last value stack without using "stack.pop".

import java.util.stack;  stack stack = new stack(); stack.push("something"); stack.push("something new"); 

class stack extends class vector, has lastelement() , firstelement() method return last respectively first element in collection.

after doing test can confirm top of stack (the last element pushed in) last element, bottom of stack first element. note if such access necessary, might indicate need different data structure stack, depends on context. @ rate, vector allows random access.

if need last element definition without popping it, using peek() suggested elliott in comment appropriate method.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -