Methods in the Stack Interface

 

 

Stack Interface

void

clear ()

Removes all items from this stack.

Object

clone ()

Returns a shallow copy of this stack.

Collection

collectionView ()

Returns a collection view of the items contained in this stack.

boolean

equals (Object other)

Returns true if the other object is a stack that equals this stack.  To be equal two stacks must contain equal items appearing in the same order.

int

hashCode ()

Returns the hash code value for this stack.

boolean

isEmpty ()

Returns true if this stack contains no elements.

Iterator

iterator ()

Returns an iterator over the items contained in this stack.  The iterator provides the items in their stack order, that is, from top to bottom.  The iterator should not support removal.

Object

peek ()

Returns the item at the top of this stack without removing it from the stack.  Throws an exception if the stack is empty.

Object

pop ()

Returns the item at the top of this stack and removes it from the stack.  Throws an exception if the stack is empty.

void

push (Object item)

Pushes an item onto the top of this stack.  Throws an exception if the item is null.

int

size ()

Returns the number of items in this stack.

Object[ ]

toArray ()

Returns an array containing all the items in this stack.  The top of the stack corresponds to the first item in the array.

String

toString ()

Returns a string that lists the items in this stack.  The top of the stack corresponds to the first item in the string.

 

 

martin@cc.wwu.edu
Disclaimer

Copyright Martin Osborne 1998-2001
  All rights reserved