Source Code : Generic stack demo with annotation

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Generic stack demo with annotation

      

public class Stack<T> {
  private T[] items;

  private int top;

  @SuppressWarnings("unchecked")
  public Stack(int size) {
    items = (T[]) new Object[size];
    top = -1;
  }

  public void push(T item) throws Exception {
    if (top == items.length - 1)
      throw new Exception("Stack Full");
    items[++top] = item;
  }

  public T pop() throws Exception {
    if (top == -1)
      throw new Exception("Stack Empty");
    return items[top--];
  }
}

   
    
    
    
    
  

Thank with us