the problem is in your isEmpty() method. Try do something like this
public boolean isEmpty()
{
for (T element : stack)
{
if(element != null)
{
return false;
}
}
return true;
}
another problem is your size function, it always returns the length of the array.
try do something like this:
public int size()
{
int count = 0;
for (T element : stack)
{
if(element != null)
count++;
}
return count;
}