• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Linked List in Java

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, looks like this:

Zat help?
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic