Make a linked list without pointers?
Short answer: Use the Vector class in java.util. It can do anything a linked list can do and a little more and saves you a lot of coding which, after all, is the point of OOP and the class library. However it is array based so insertions or deletions from the middle of a Vector are not as efficient as with a true linked list. Long answer: Object variables in Java are all references. A reference acts like a pointer in most other languages. (Though they’re handles, not pointers, in most Java implementations. The notable exception is Microsoft’s.) The main difference is that you can’t do pointer arithmetic on references. Therefore wherever you’d use a pointer to an object in C++, in Java you should just use the object itself. On the other hand the primitive data types (int, float, double, char, byte, short, long and boolean) are not references. If you want to get a reference to one of these you need to wrap it in a class first. Java provides ready-made type-wrapper classes in the java.lan
Related Questions
- Is the list of licensed baseball bats (linked above) a complete list of all the bats that are "legal" for use in the Little League (Majors) Division and below?
- Does the course include practical pointers on creating my vendor list, setting my prices, marketing my business, and preventing problems before they occur?
- Make a linked list without pointers?