+2 votes

How to implement linked list in Java as there is no pointer concept available in Java. Also if it's implemented then which part of Java take over the concept of pointers. 

asked Jan 30 in Computer Science - IT by Guptakunal42
retagged Feb 7 by slow_learner | 50 views

2 Answers

+2 votes

Yes, JAVA doesn't have pointer concept. But, whenever an object created with variable it is actually a reference like a pointer leads towards the object. Thus, Java contains referencing or pinter concept explicitly.

For example,

If I am creating a new object called kitty for my class Dog,

Dog kitty = new  Dog(); It actually means that it creates an object and referencing this newly created object to the so-called local variable or object kitty. So, if you assign a new variable to this object kitty, it just copying the references, not the value. Thus Java contains the linked list or list concept explicitly and it keeps tracks of the references which are assigned to. 

So, in this way we can presume that Java comprises of list and linked list concepts indirectly(or we can say that not mentioned as like in c , cpp and other languages) even though it doesn't allow pointer concepts but through the references methods. 

answered Feb 1 by Aqib Muhammed
edited Feb 6 by Aqib Muhammed
+1 vote

To implement this we have Java util class for rescue :


Class LinkedList<E>

The class implements the Queue interface, providing first-in-first-out queue operations for add, poll, etc. Other stack and deque operations could be easily recast in terms of the standard list operations. They're included here primarily for convenience, though they may run slightly faster than the equivalent List operations.

Find more at Oracle Docs

answered Jan 30 by django