If the Java language lacks pointers, how do I implement classic pointer structures like linked lists?
Ans : Use object references in place of pointers. Object references in Java are like object pointers minus the arithmetic. The Java language lets you point to (refer to) objects; it just doesn’t let you change numbers into references, references into numbers, or otherwise treat references in any numerical way. This property makes it straightforward to implement classic pointer-dependent data structures such as lists and trees. The following example shows a minimal linked-list implementation of a stack: /** A bare-bones stack class that holds objects of any class. */ public class SimpleStack { LinkedObject stackTop = null; public void push(Object obj) { if (obj != null) { stackTop = new LinkedObject(obj, stackTop); } } public Object pop() { if (stackTop != null) { Object oldTop = stackTop.value; stackTop = stackTop.nextObject; return oldTop; } return null; } } /** A bare-bones class for linking objects of any class. */ class LinkedObject { Object value; LinkedObject nextObject; LinkedOb