java.util.LinkedList class
java.util.LinkedList class
- We can store group of objects in LinkedList object.
- Here group of objects means, it can allow us to store same type of objects and different type of objects.
- Same type means, assuming that all objects are in the form of integer types.
- Different type means, assuming that all objects are in the form of integer, float, String, Student and Customer types also.
- It uses doubly-linked-list to store the objects.
- It extends the AbstractList class which is abstract class and implements List and Deque interfaces.
- Size will increase dynamically.
- LinkedList is non synchronized.
- The process of LinkedList is very slow, if you are inserting and removing the objects from middle of the LinkedList.
- We will get the output according to insertion order.
- Allows duplicate objects.
--------------------------------------------------------------------------------------------
Program : Example on LinkedList class
Program name : LLDemo1.java
Output :
[1, Nireekshan, Nireekshan, A, 1.1, 1.12345]
import java.util.LinkedList;
class LLDemo1
{
public static void main(String args[])
{
LinkedList linkedList = new LinkedList();
linkedList.add(1);
linkedList.add("Nireekshan");
linkedList.add("Nireekshan");
linkedList.add("Nireekshan");
linkedList.add('A');
linkedList.add(1.1f);
linkedList.add(1.12345);
System.out.println(linkedList);
}
}
Compile : javac LLDemo1.java
Run : java LLDemo1
Output :
[1, Nireekshan, Nireekshan, A, 1.1, 1.12345]
--------------------------------------------------------------------------------------------
Thanks for your time.
Nireekshan