Linked List:
Linked List Is part of collection framework and it is
available in “java.util” package .
Linked List implements List, Deque, Cloneable, Serializable
interfaces and extends Abstract Sequential List class.
Linked List class maintains insertion order.
Java LinkedList class can contain duplicate elements.
Manipulation with Linked List is faster than Array List
because it internally uses doubly LinkedList, so no bit shifting required in
memory. so entire memory will not effect.
A linked list consumes more memory because it uses doubly
linked list it contains collection of nodes each node consists of 3 parts 1)
previous node 2) data 3) next node
Doubly Linked List − Items can be navigated forward and
backward way.
Java LinkedList class is non synchronized.
Linked is not thread safe you must explicitly synchronize
concurrent modifications to the linked list in a multi-threaded environment.
Creation of LinkedList:
Syntax:
LinkedList <E> llist = new LinkedList<E>();
LinkedList <E> llist = new LinkedList <E>(int
initialcapacity);
Here, E represents element data type
Methods of LinkedList:
Some of the important methods in linked list
offer(E e):
this method is used to adds the specified element as the last element of a
list.
offerFirst(E e): this
method is used to inserts the specified element at the front of a list.
offerLast(E e): this
method is used to inserts the specified element at the end of a list.
peek(): this method is used to retrieves
the first element of a list
peekFirst():
this method is used to retrieves the first element of a list or returns null if
a list is empty.
peekLast(): this
method is used to retrieves the last element of a list or returns null if a
list is empty.
poll(): this method is used to
retrieves and removes the first element of a list.
pollFirst():
this method is used to retrieves and removes the first element of a list, or
returns null if a list is empty.
pollLast():
this method is used to retrieves and removes the last element of a list, or
returns null if a list is empty.
pop(): this method is used to pops an
element from the stack represented by a list.
push(E e):
this method is used to pushes an element onto the stack represented by a list.
Java Code:
No comments:
Post a Comment