I am trying to join String
elements of Set
with semicolon.
Set<String> elements = new Set<String>{
'foo',
'bar'
};
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){
System.debug(element);
}
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), ';'));
DEBUG|foo;bar
So do you have idea, why is it happening?