This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Linked List in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Linked List in Java" Watch "Linked List in Java" New topic
Author

Linked List in Java

Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
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

Joined: Jul 16, 2001
Posts: 83
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

Joined: Jan 29, 2003
Posts: 8791
Yup, looks like this:

Zat help?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Naren
Greenhorn

Joined: Jul 21, 2003
Posts: 23
Here is the sample code from the book:
"Data Structures and Algorithms in Java" by Robert LaFore.

Published: NOV 06, 2002
ISBN: 0672324539


<a href="http://www.mqtips.com" target="_blank" rel="nofollow">MQMessenger</a> - free Java app for MQSeries
Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
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

Joined: Aug 20, 2001
Posts: 1817

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.)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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?
 
 
subject: Linked List in Java
 
Similar Threads
Implement linked list in java
Hashtables in java might confuse the general hashtable understanding
One more question help plz
Implement a Singly Linked Sorted List (SortedLinkedList<Comparable>) in Java
doubly linked list