Generic collections

  1. Queue Java Queue interface orders the element in FIFO(First In First Out) manner. In FIFO, first element is removed first and last element is removed at last.

    (1). 方法:

    Add()-Adds an element at the tail of

    peek()-To view the head of queue without removing it. Returns null if queue is empty.

    element()-Similar to peek(). Throws NoSuchElementException if queue is empty.

    remove()-Removes and returns the head of the queue. Throws NoSuchElementException when queue is impty.

    poll()-Removes and returns the head of the queue. Returns null if queue is empty.

  1. Stack

    (1). 方法:

    push(Object element) : Pushes an element on the top of the stack.

    pop() : Removes and returns the top element of the stack. An ‘EmptyStackException’ exception is thrown if we call pop() when the invoking stack is empty.

    peek( ) : Returns the element on the top of the stack, but does not remove it.

    empty() : It returns true if nothing is on the top of the stack. Else, returns false.

    search(Object element) : It determines whether an object exists in the stack. If the element is found, it returns the position of the element from the top of the stack. Else, it returns -1.

results matching ""

    No results matching ""