I am trying to join String elements of Set with semicolon.

Set<String> elements = new Set<String>{
System.debug(String.join(elements, ';'));

getting the following exception

Argument must implement Iterable

Is it weird, as we can easily iterate Set with foreach loop

for(String element :elements){

It means, that Set<T> implements Iterable<T>, doesn't it? From documentation about String.join method:

Joins the elements of the specified iterable object, such as a List, into a single String separated by the specified separator. Signature

However, String.join with List collection works good.

System.debug(String.join(new List<String>(elements), ';'));


So do you have idea, why is it happening?


Looks like Set does not implement iterable.


System.debug(new List<Object>() instanceof Iterable<Object>);

Output: Compile failure on line 2, column 14: Operation instanceof is always true since an instance of List<Object> is always an instance of Iterable<Object>


System.debug(new Set<Object>() instanceof Iterable<Object>);

Output: 11:38:23.10 (10761093)|USER_DEBUG|[2]|DEBUG|false

Not the answer you're looking for? Browse other questions tagged or ask your own question.