Java Help - Linked Lists

If you don’t know what Linked Lists are, you shouldn’t be here. I’m trying to figure out how to remove an object from the beginning of a linked list. Here’s the files I have so far; the //??? is what I’m stuck on. (Driver),,

//if there is only one node, delete the entire list.
if ( == null) list = null;
//otherwise, make the first node point to the second node.
else list =;

Let me know if that works.

Hey, it worked! Awesome!

… and I TOTALLY screwed up in the ListNode.toString() n.n;

On second thought, you can actually do it in one line:
list =;

Look at the code again and you’ll see why. :sunglasses:

As long as you always set next to null beforehand (constructors work wonders for this), Cid’s code should work. I could totally show you how to do it in C++, it’s the same concept.

By default objects are set to null in Java, so you don’t have to explicitly do that.

That would be damn nice.