File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Linked List Remove? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Linked List Remove?" Watch "Linked List Remove?" New topic

Linked List Remove?

Luke Gotto

Joined: Apr 04, 2008
Posts: 2
When i run this it removes all of the elemets of the list except the last one... Any ideas why it is not geting to the last node?

public E remove() // delete link with given key
E tmp;
tmp = null;
cursor = first;
previous = first;

if (cursor == null)
return null;
tmp = first.item;
previous = cursor;
first =;
length = length -1;

return tmp;

marc weber

Joined: Aug 31, 2004
Posts: 11343

Sorry, I really can't figure out how this is intended to work. I think it might help if you explained the steps in English. It's a good way to check your own logic, and it would give us a clear idea of what you're expecting to happen.

(Code Tags with clean indentation would also help.)

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Linked List Remove?
It's not a secret anymore!