I have a exercise where I have to write a Stack class with the push and pop method. The code compiles and works as it should. My question is: Are there better practices to use in my code? Is there something I should avoid doing?
public class Stack {
private final int INCREMENTSIZE = 1024;
Integer position = 0;
int[] list = null;
public Stack(){
list = new int[INCREMENTSIZE];
}
public void push(Integer i) {
if(position == list.length) {
list = Arrays.copyOf(list, list.length + INCREMENTSIZE);
}
list[position++] = i;
}
public Integer pop(){
return list[--position];
}
}