HashSet add() Method in Java

The add(E element) method of HashSet inserts the specified element into the set. It returns false if the set already contains the specified element otherwise returns true. Syntax Parameters e is the element to insert into set Program 1 Output Set elements: [50, 20, 40, 10, 30] Program 2 Output Read more…

LinkedList add() Method in Java

The add(E element) of LinkedList appends the specified element at the end of the list. We can also add an element at a specific position using the add(int index, E element) method. Syntax 1 Parameters e is the element to be added to the linked-list Return Value It returns true Read more…

LinkedList addFirst() Method in Java

The addFirst(E element) method of LinkedList appends the specified element at the beginning of this linked list. It does not return anything. Syntax Parameters e is the element to be added to the linked-list Return Value It doesn’t return anything Program Output Linked List elements: [5, 7, 9, 11] Linked Read more…

LinkedList addLast() Method in Java

The addLast(E element) method of LinkedList appends the specified element at the end of this linked list. It does not return anything. Syntax Parameters e is the element to be added to the linked-list Return Value It doesn’t return anything Program Output Linked List elements: [5, 7, 9, 11] Linked 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…