I was looking around online and found a class to use ArrayLists in Stack operations. After looking up the arraylist I noticed the <E> designation there too. I followed it all the way back to Collection and I don’t understand what the <E> would be in this example:
public class MyStack<E> {
private ArrayList<E> arrList;
public MyStack() {
arrList = new ArrayList<E>();
}
public void push(E item) {
arrList.add(item);
}
... more methods...
}
What does “E” refer to? If it was explained in the docs I either missed it or just don’t understand it.
<E>represents the type of data that you will use in yourStack. The simple example will be enough:This is called Java Generics