LinkedList clear() method with example in java

The clear(E element) method of LinkedList removes all the elements from this list. The linked list becomes empty as a result of this call. Syntax Parameters This method doesn’t take any parameter. Return Value It does not return anything Program Output Linked List elements: [5, 7, 9, 11] Linked List Read more…

LinkedList contains() method with example in java

The contains(E element) method of LinkedList checks if the LinkedList contains the specified element or not. It returns true if the linked list contains the specified element. Syntax Parameter e is the element to check in the linked-list Returns Value It returns true if the linked-list contains specified element otherwise Read more…

LinkedList element() method with example in java

The element() method of LinkedList retrieves but does not remove the first element of this linked list. It throws NoSuchElementException if the linked list is empty. Syntax Parameters It doesn’t take any parameter Return Value It returns the first element of this linked list. Exception throws NoSuchElementException if the linked Read more…

LinkedList getFirst() method with example in java

The getFirst() method of LinkedList returns the first element of this linked list. It throws NoSuchElementException if this linked list is empty. Syntax Parameters it doesn’t take any parameter Return Value It returns the first element in this linked-list Exception throws NoSuchElementException if this linked-list is empty Program 1 Output Read more…

LinkedList getLast() method with example in java

The getLast() method of LinkedList returns the last element of this linked list. It throws NoSuchElementException if this linked list is empty. Syntax Parameters it doesn’t take any parameter Return Value It returns the first element in this linked-list Exception throws NoSuchElementException if this linked-list is empty Program 1 Output Read more…

LinkedList indexOf() method with example in java

The indexOf(E element) method of LinkedList returns the first occurrence of the specified element in this linked list. Syntax Parameter e is the element to find in this linked-list Return Value It returns the index of the first occurrence of the specified element Program Output Linked List elements: [5, 7, Read more…