Question: Write a method that adds an element to a HashSet Write a static method addIfNotThere ( ) that will add an element to a HashSet
Write a method that adds an element to a HashSet
Write a static method addIfNotThere that will add an element to a HashSet only if it does not already exist, and will print out one of the following messages:
Messages:
If the element already exists in the HashSet, the method prints element already exists in the HashSet
If the element is added, the method prints element was added to the HashSet
Parameters: a HashSet of String, and a String to add
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
