LinkedList class belongs to java.util package.
It implements List, Deque, Cloneable and Serializable interface. LinkedList is the doubly-LinkedList implementation of the List and Deque interface.
It implements List, Deque, Cloneable and Serializable interface. LinkedList is the doubly-LinkedList implementation of the List and Deque interface.
Key feature of LinkedList:
1. It is non-synchronized.
2. LinkedList is preferred over ArrayList if operations like insertion or deletion needs to be done in bulk.
3. LinkedList allows addition of null element.
Now let’s look at the ways in which you can create LinkedList in java. Please click on each to learn the creation technique.
· LinkedList<E> myList = new LinkedList <E>(); //<E> denotes Generics usage
· LinkedList<E> myList = new LinkedList <E>(Collection c);
Simple Example:
Now let’s look at different ways in which you can use the LinkedList that you created.
package
javaRadarLinkedList;
import
java.util.LinkedList;
public class SimpleLinkedList
{
public static void main(String[] args) {
//create LinkedList
LinkedList<String>
javaRadarList = new
LinkedList<String>();
//Add elements
to LinkedList
javaRadarList.add("Java");
javaRadarList.add("Spring");
javaRadarList.add("Hibernate");
javaRadarList.add("EJB");
System.out.println(javaRadarList);
}
}
Now let’s look at different ways in which you can use the LinkedList that you created.
LinkedList operations
Traverse LinkedList
Convert
· LinkedList to ArrayList
ArrayList or LinkedList. Which one to use?(Click to see the difference between two and decide)
No comments:
Post a Comment