• Post Reply Bookmark Topic Watch Topic
  • New Topic

difference between removeFirst() remove()  RSS feed

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IS there any difference between removeFirst() method and remove() method in LinkedList? :roll:
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course! removeFirst() takes no argument, and always removes the first element from the list. remove() takes an argument, and removes the argument from the list, if in fact the list contains that argument.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oooh. Check your API Ernest

public E remove()
Retrieves and removes the head (first element) of this list.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:
Oooh. Check your API Ernest



Grrr OK, I really need to spend some serious time on a Tiger-based project. A lot of little "new in Java 5" bits like this are still unfamiliar to me. Sorry about that.

Looks like the older removeFirst() and the newer remove() (which comes from the JDK 1.5 "Queue" interface) do, indeed, do the same thing. In fact, this is from the LinkedList source:

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The developer must have been being paid by the number of methods (s)he wrote
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!