Reputation: 57
in my course i am actually at Lists and how to work with them. There is one command i dont fully get. I think the topic lists is pretty roff so please go easy on me.
Person node = list.remove(0);
Person is the Class node the new Oject
What is inside of node now is what were inside of list.(index 0), why is that, didn't i remove what is inside of the list ? Can i handle it the same way like:
Person node = list.get(0); list.remove(0);
Upvotes: 1
Views: 51
Reputation: 6017
Person node = list.get(0);
list.remove(0);
is equivalent to:
Person node = list.remove(0);
It is how the method is defined in the List
interface. When you remove, the method also returns the Object removed. More in docs here: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#remove-int-
Upvotes: 1