Add elements in HashSet

We can use add() method of HashSet to add elements to HashSet collection boolean add(Object obj) It adds the element obj to the Set. Example import java.util.HashSet; public class HashSetAddExample {    public static void main(String args[]) {             HashSet<String> hs =  new HashSet<String>();         hs.add("java");   […]

Share this article on

Methods in HashSet

There are different methods defined in HashSet to perform various operations 1) boolean add(Object obj) 2) void clear() 3) Object clone() 4) boolean contains(Object obj) 5) boolean isEmpty() 6) boolean remove(Object obj) Let’s discuss each of these methods in detail boolean add(Object obj) It adds the element obj to the Set. Example :  HashSet<String> hs […]

Share this article on
< Previous Next >