Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linked List in Java

 
Harry Singh
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can we implement linked list in java.Though there are Collection classes for this purpose and we have LIst interface in that.. but is it possible to implement linked list as we dont have any pointers in Java..
Can i get some useful links for data structures in Java.
Thanks in advance.
Regards,
Harry
 
Roy Tock
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We *do* have pointers in Java. They're called "references". Java doesn't allow pointer arithmetic, but mostly "references" are just pointers.
See the Java Specification for evidence & discussion.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, looks like this:

Zat help?
 
Naren
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the sample code from the book:
"Data Structures and Algorithms in Java" by Robert LaFore.

Published: NOV 06, 2002
ISBN: 0672324539
 
Harry Singh
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI pals,
thanks for all ur resplies.. but we do have a class LinkedList in Collection interface. so is it same as this linked list.
can we use it in same contextg as linked list of data structures. IF it is the same, then why do we need to make our own LinkedList.
Regards,
Harjinder
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you are doing an exerice for school work, you do not need to make your own LinkedList. The one in the Collections API will do just fine (and probably better; I imagine that it is optimized for iteration, where a standard "you-write-it-yourself" one isn't).
The only drawback is that the Collections LinkedList only works with objects; primitives are not acceptable. (Although with the forthcoming release of Java 1.5, the auto-boxing feature will automatically wrap your primitives in the appropriate wrapper class, so even this drawback is soon to go away.)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And wouldn't it be nice to have a linked list of Galoshes so you don't have to cast (Galosh) every time you get one out of the collection?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic