- Single Linked List
- Doubly Linked List (java has doubly linkedList)
LinkedList Class
-Uses doubly linked list to store the elements
-Can contain duplicate elements
-not syncronized (It is not Thread safe)
-Maintains insertion order
-No Random access
-Manipulation fast because no shifting needs to be occurred.
Example of LinkedList Java Code..
import java.util.Iterator;
import java.util.LinkedList;
public class LinkedListExample {
public static void main(String[] args) {
LinkedList ll = new LinkedList();
ll.add(1);
ll.add(2);
ll.add(3);
ll.add(1,"Najathi");
Iterator i = ll.iterator();
while(i.hasNext()){
System.out.println(i.next());}
}
}
No comments:
Post a Comment