linkedlist in java linkedlist example in java linkedlist implementation in java linkedlist in java example linkedlist in java code linkedlist in java api difference between arraylist and linkedlist in java difference between linkedlist and vector in java difference between linkedlist and array difference between linkedlist and arraylist in java example linkedlist in java 6 linkedlist class in java example linkedlist in java code example linkedlist api java linkedlist java api 7 methods of linkedlist in java methods of linkedlist methods of linkedlist class in java
Linked List:
Linked
List is one of the bottom most 1D concurrent sub class or 1D Collection
framework abstract classes,
an object of linked list is one of the collection
frame work variable creating an object or linked list is making use of
linkedlist class.
LinkedList ll=new Linkedlist();
Linked List Constructors and Methods :
1)
Linked
List():
This constructor is used
for creating an object of LinkedList class without specifying initial number
nodes to be created.
2)
Linked
List(int):
This constructor is used for creating an object of LinkedList by
specifying initial number of nodes to be created.
3)
public void addFirst(object):
This method is used for inserting an object into any collection frame
work variable at first of the Linked list object.
4)
public void addLast(object) :
This method is used for inserting an object into any collection frame
work variable at last of the Linked List object.
5)
public
object getFirst():
This method is used for retrieving the object from any collection frame
work variable at first of any Linked List.
6)
public
object getLast():
This method is used for retrieving the object from any collection frame
work variable at last of any Linked List.
7)
public
object removeFirst():
This method is used for removing the object from collection frame
variable at first of the Linked List.
8)
public
object removeLast():
This method is used for removing the object from collection frame
variable at last of the linked list.
Difference
Between LinkedList and Vector class :
1)
The functionality of vector class object is more
or less similar to LinkedList and ArrayList classes. But vector object class
belongs to synchronized and LinkedList class object belongs to non –
synchronized.
2)
And also
comparing to vector and arraylist, linkedlist take more memory space and
retrieval time is more.
Difference Between LinkedList and Array :
The size of Linkedlist is dynamic in
nature and it allows to store the both homogeneous and heterogeneous elements. The
size of Array is fixed and it allows to store only homogeneous values.
Advantages:
If we write an java application in the concept of linkedlist then it eliminates
the all the
problems of arrays and it provides
the following advantages
1) linkedlist class object allows us to store both homogeneous
and heterogeneous values
2) linkedlist class object always posses dynamic
size in nature
3) With linkedlist class object one can insert an
element either in the beginning or in the
last or in the middle
that is dynamic insertion are not permitted
Dis
advantages:
1) Linkedlist takes more memory space because both
data and address part of the
nodes are collectively storing in heap
memory. Due to more memory space performance
of an application may be reduced.
2) Retrieving the data from linked list will take
more amount of time because after
processing the current node value, before processing the next node value jvm
explicitly
retrieves address of next node from address part of current node.
The Following program illustrate concepts of LinkedList Such all methods that are going to use in the below program
//LinkedListDemo.java
import java.util.*;
Class LinkedListDemo
{
Public static void main(String
args[])
{
LinkedList ll=new LinkedList();
System.out.println(“Content of
ll=”+ll);
System.out.println(“is linked list
empty =”+ll.isEmpty());
System.out.println(“Size of
ll=”+ll.size());
//add the data to LinkedList Object ll
ll.add(new Integer(20));
ll.add(new Integer(30));
ll.add(new Integer(40));
System.out.println(“Content of
ll”+ll);//[20,30,40]
System.out.println(“is LinkedList empty
?”+ll.isEmpty());//false
// add the element 5 to Linked list at
first
ll.addFirst(new Integer(10));
//add the element 50 to Linked List at
Last
ll.addLast(new Integer(50));
System.out.println(“Content of ll=”+ll);
System.out.println(“Size of
ll=”+ll.size());
//Extracting the data from Linked List
System.out.println(“Extracting the data
from linked list object ll by using iterator”);
Iterator itr=ll.iterator();
int s=0;
for( ;itr.hasNext(); )
{
Object obj=itr.next();
Integer io=(Integer)obj;
int
x=io.intValue();
System.out.println(x);
s=s+x;
}
ListIterator litr=ll.listiterator();
While(litr.hasNext())
{
Object obj1=litr.next();
System.out.println(obj1);
}
System.out.println(“Extracting
the data from Linked list by using List iterator”);
While(litr.hasPrevious())
{
Object obj2=litr.Previous();
Object obj2=litr.Previous();
Integer io1=(Integer)obj2;
int x1=io1.intValue();
System.out.println(x10;
}
}
}
}
Data Extraction Interfaces:
Data Extraction Interfaces:
1- D and 2-D Collection Frame work classes are
To read the values dynamically from keyboard their is a class.
No comments:
Post a Comment