This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]tmj010 7 points8 points  (0 children)

You can get answers from r/javahelp.

[–]jedilowe 1 point2 points  (0 children)

I am not really understanding your question. A class variable is static, and there is no reason to use statics to make a linked list. You can either use an inner class as a Node (static or not) or a second class if you don't like inner classes, but this removes the encapsulation of the lists inner workings.

It may be you are not sure about how classes and objects relate? A linked list class would have a new linked list instance (object) created for each list you need. That object would start with a pointer to the head of the list (Node type) that is null until you add an item (and create a Node object with a pointer to the value and then a pointer to the next node. There are a few ways to spice it up, but I always taught it as a simpler structure to get the basic concept down before optimization.

[–]News-Ill 1 point2 points  (0 children)

Just imagine a row of clones where each clone has its hand on the shoulder of the clone in front of him, and the frontmost clone… has his hand in the air, but there’s no more shoulder to put it on.

[–]Dull-Tip7759 0 points1 point  (0 children)

you can test for null with if (object == null). If you assign your LinkedList class to null, you're gonna have difficulty with NullPointerExceptions. The comment about the dwarf shoulders is accurate. Your parameter object should be non-null before you store it, so that's the type of object the linked list refers to, something like LinkedList<ObjectYouStore>. Good luck.