r/javahelp 22h ago

linked lists

-- solved thank you all

what is the difference between accessing the next node using a get method or without, as in: "current.next" vs "current.getNext()" and the same applies for accessing an element, whats the difference between use the get or not, as in: "current.element" vs "current.getElement()" where current is just the name for the node variable. ive looked at so many different explanations but i cant seem to grasp the idea
edit: this is from a data structures pov, im implementing methods for the singly and doubly linked list classes in java
i want to know if they return different things or if using .next or .getnext makes a difference in the outcome, is there a scenario i should be using strictly .next or .getnext, and the getter method has no further conditions its just {return next}

3 Upvotes

19 comments sorted by

View all comments

0

u/LetUsSpeakFreely 22h ago

Not sure what implementation you're looking at, but that's not typically how you navigate a linkedlist. Use the methods defined in the List interface, that's why it's there. If you know you're going to look at every element in the list then use an iterator (list.iterator()).

0

u/gerladokennedy 22h ago

im not necessary navigating lists in a normal code this is from a data structures perspective, im creating methods for the singly or doubly linked list classes

1

u/LetUsSpeakFreely 22h ago

No, this is a forum for help with Java. Hence the name, javahelp.

1

u/gerladokennedy 22h ago

yes im implementing this in java