Using LinkedList to populate a stack of Long type elements. For some reason, value null is added instead of 15 when I call my push method. Why is that?
import java.util.LinkedList;
public class LongStack {
public static void main (String[] argum) {
LongStack s = new LongStack();
s.push(15);
System.out.println(s);
}
private LinkedList<Long> l;
LongStack() {
l = new LinkedList<Long>();
}
public void push (long a) {
l.add(a);
}
OK, i found the problem. My bad. There was an overriding toString method (return null;
) later in my code that wasn't implemented. But thanks for the tips.