Skip to content

Tag Archives: java-hashset

Given an array of integers arr[], find the number of recycled pairs in the array. A recycled pair of two numbers {a, b} has the… Read More
The Java.util.HashSet.iterator() method is used to return an iterator of the same elements as the hash set. The elements are returned in random order from… Read More
The Java.util.HashSet.clear() method is used to remove all the elements from a HashSet. Using the clear() method only clears all the element from the set… Read More
The Java.util.HashSet.clone() method is used to return a shallow copy of the mentioned hash set. It just creates a copy of the set. Syntax: Hash_Set.clone()… Read More
The Java.util.HashSet.contains() method is used to check whether a specific element is present in the HashSet or not. So basically it is used to check… Read More
HashSet remove() method is used to remove a particular element from a HashSet. Note that it is only after JDK version 1.2 and ahead, and… Read More
The Java.util.HashSet.isEmpty() method is used to check if a HashSet is empty or not. It returns True if the HashSet is empty otherwise it returns… Read More
The Java.util.HashSet.size() method is used to get the size of the HashSet or the number of elements present in the HashSet. Syntax: Hash_Set.size() Parameters: This… Read More
The Java.util.HashSet.add() method in Java HashSet is used to add a specific element into a HashSet. This method will add the element only if the… Read More
Suppose we have an elements in ArrayList, we can count the occurrences of elements present in a number of ways. HashMap This data structure uses… Read More
Below given are some methods which can be used to convert Stream to Set in Java. Method 1 : Using Collectors Stream collect() method takes… Read More
Set interface extends Collection interface and Collection has stream() method that returns a sequential stream of the collection. Below given are some examples to understand… Read More
Given a list (ArrayList or LinkedList), convert it into a set (HashSet or TreeSet) of strings in Java. Method 1 (Simple) We simply create an… Read More
Given a set (HashSet or TreeSet) of strings in Java, convert it into a list (ArrayList or LinkedList) of strings. In java, Set interface is… Read More

Start Your Coding Journey Now!