Challenges

Add Element to Set

Welcome to Sets in Apex! A Set is an unordered collection of unique elements. Complete the method addToSet that accepts a Set parameter stringSet and a String parameter element. Add the element to the set and return the modified set.

Example:

  • Input: stringSet = {'apple', 'banana'}, element = 'cherry'
  • Output: {'apple', 'banana', 'cherry'}

Hint: Use the add() method to add an element to a set.

Editor
Test Results

Result Panel

Hit the run button to test your code!