HashSet clear() Method in Java

The clear() method of HashSet removes all the elements from the HashSet. The HashSet becomes empty after the call to the clear() method. Syntax Parameters It does not take any parameter and does not return anything. Return Value It does not return anything. Program 1 Output Set elements before clear: Read more…

HashSet isEmpty() Method in Java

The isEmpty() method of HashSet checks if the HashSet is empty or not. If the HashSet is empty then it returns true otherwise returns false. More formally, it returns true if the size of the HashSet is equal to zero. If the size is greater than zero then the isEmpty() Read more…

HashSet clone() Method in Java

The clone() method of HashSet returns a shallow copy of this HashSet instance. It overrides the clone() method of Object. Syntax Parameters It does not take any parameter Return Value it returns a shallow copy of this HashSet instance. Program 1 Output Set elements : [50, 20, 40, 10, 30] Read more…

HashSet remove() Method in Java

The remove(Element e) method of HashSet removes the specified element from the set. Syntax Parameters e is the element to be removed Return Value It returns true on successful removal of the element otherwise false if the element is not found in the HashSet. Program Output Set elements : [50, Read more…

HashSet size() Method in Java

The size() method of HashSet returns the number of elements available in the HashSet. Syntax Parameters It does not take any parameter Return Value It returns the number of elements in the HashSet Program 1 Output Set elements: [50, 20, 40, 10, 30] Number of elements in set: 5

HashSet contains() Method in Java

The contains(Element e) method of HashSet checks if the HashSet contains the specified element or not. It returns true if the HashSet contains the specified element otherwise it returns false. Syntax Parameters e is the element whose presence in this HashSet is to be checked. Return Value It returns true Read more…

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…