filmov
tv
Java Collections Tutorial 04 | LinkedList in Java | LinkedList |Java9s.com

Показать описание
LinkedList is an Ordered collection. It is an interesting implementation of List and it has some extra functionality compared to ArrayList and Vector.
So, if you take a look at the hierarchy of LinkedList, you can see that it is from List and it is also implmenting the Queue and Double ended queue interfaces.
So, most of the methods from List have been discussed in ArrayList module. We will focus on the queue and double ended queue features of LinkedList.
So, what is the difference between the normal list based implementations like ArrayList, Vector vs LinkedList.
With ArrayList or Vector, when we add an element without specifying an index, they place that element at the end of the list by default.
AddFirst method adds element to the beginning of List
AddLast method adds the element at the end of the List
getFirst method returns the first and getLast returns the last element in the list
removeFirst and removeLast methods remove the first and last elements respectively.
With LinkedList, because it is a Doubled ended queue, we can add the element to the front or at the end of the list.
To enable this, LinkedList implements a range of methods to be able to add, remove and get elements from front or from end of the collection.
So, LinkedList implementing the Dqueue interface is like double edged sword. If you think the element you want can be reached from end of collection, we can use this or if from the first, we then have normal iterator.
So, if you take a look at the hierarchy of LinkedList, you can see that it is from List and it is also implmenting the Queue and Double ended queue interfaces.
So, most of the methods from List have been discussed in ArrayList module. We will focus on the queue and double ended queue features of LinkedList.
So, what is the difference between the normal list based implementations like ArrayList, Vector vs LinkedList.
With ArrayList or Vector, when we add an element without specifying an index, they place that element at the end of the list by default.
AddFirst method adds element to the beginning of List
AddLast method adds the element at the end of the List
getFirst method returns the first and getLast returns the last element in the list
removeFirst and removeLast methods remove the first and last elements respectively.
With LinkedList, because it is a Doubled ended queue, we can add the element to the front or at the end of the list.
To enable this, LinkedList implements a range of methods to be able to add, remove and get elements from front or from end of the collection.
So, LinkedList implementing the Dqueue interface is like double edged sword. If you think the element you want can be reached from end of collection, we can use this or if from the first, we then have normal iterator.
Комментарии