Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
sankrish
Posts: 54
Registered: ‎05-04-2011
My Device: 1
My Carrier: developer

Stack

I'm using Stack which consists of value  "1" as top of stack and value "2" as 2nd position and value "3" on 3rd position.. i have retrieved the value "1" by stack.peek().. now, i want to get value "2" which was in 2nd postion of the stack..Is there any method available to retrieve the value?

                                                         

santhanam
Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Stack

The method peek() just gives you the value on the top of the stack.

 

If you want to check the element below the top element you will need to use the method pop() - it returns the element on the top of the stack AND removes it from the stack  . So when you call pop() it returns 1 , when you call pop() again it will return 2.

 

Of course you can write your own stack implementation and implement some specific logic there but in the classic version peek just check the element on top and pop removes it.

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Regular Contributor
sankrish
Posts: 54
Registered: ‎05-04-2011
My Device: 1
My Carrier: developer

Re: Stack

I removed topofstack value using pop() and then called peek() method to retrieve the second value..It works.

santhanam
Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Stack

Ok :smileyhappy: I glad you solved your problem. If thats all you can click accept as solution button and mark the thread as solved.
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.