![]() ![]() Push(E e): This method Pushes an element onto the stack represented by this list. Pop(): This method Pops an element from the stack represented by this list. PollLast(): This method retrieves and removes the last element of this list, or returns null if this list is empty. PollFirst(): This method retrieves and removes the first element of this list, or returns null if this list is empty. Poll(): This method retrieves and removes the head (first element) of this list. PeekLast(): This method retrieves, but does not remove, the last element of this list, or returns null if this list is empty. PeekFirst(): This method retrieves, but does not remove, the first element of this list, or returns null if this list is empty. Peek(): This method retrieves, but does not remove, the head (first element) of this list. ![]() OfferLast(E e): This method Inserts the specified element at the end of this list. OfferFirst(E e): This method Inserts the specified element at the front of this list. Offer(E e): This method Adds the specified element as the tail (last element) of this list. ListIterator(int index): This method returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list. LastIndexOf(Object o): This method returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. IndexOf(Object o): This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. GetLast(): This method returns the last element in this list. GetFirst(): This method returns the first element in this list. Get(int index): This method returns the element at the specified position in this list. The methods of LinkedList class are shown belowĪdd(int index, E element): This method Inserts the specified element at the specified position in this list.Īdd(E e): This method Appends the specified element to the end of this list.ĪddAll(int index, Collection c): This method Inserts all of the elements in the specified collection into this list, starting at the specified position.ĪddAll(Collection c): This method Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator.ĪddFirst(E e): This method Inserts the specified element at the beginning of this list.ĪddLast(E e): This method Appends the specified element to the end of this list.Ĭlear(): This method removes all of the elements from this list.Ĭlone(): This method returns a shallow copy of this LinkedList.Ĭontains(Object o): This method returns true if this list contains the specified element.ĭescendingIterator(): This method returns an iterator over the elements in this deque in reverse sequential order.Įlement(): This method retrieves, but does not remove, the head (first element) of this list. LinkedList implements List and Deque interface, besides add() and addAll() methods you can find addFirst() and addLast(), which adds an element in the beginning or the end, respectively. List linkedList2 = new LinkedList(linkedList1) LinkedList(Collection c) This constructor builds a linked list that is initialized with the elements of the collection c. LinkedList( ) This constructor builds an empty linked list. Rightside node part is used to point to next node (Or Element) in the LinkedList. ![]() Left side node part is used to point to the previous node in the LinkedList. Internally Java Linkedlist is implemented using doubly linkedList. Pointer/Address/Reference to the next node in the LinkedList Each Node of the LinkedList contains two items:Ģ. To store the elements in a linked list we use a doubly linked list which provides a linear data structure and also used to inherit an abstract class and implement list and deque interfaces.įor official documentation on LinkeList usage, Please refer here Implements List and Queue interfaces, extends Abstract List LinkedList RepresentationĮach element in the LinkedList is called the Node. Due to the dynamicity and ease of insertions and deletions, they are preferred over the arrays. The elements are linked using pointers and addresses. Java LinkedList are linear data structures where every element is a separate object with data and address object rather than storing elements in contiguous locations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |