ToSet
Convert a collection into a Set, deduplicating automatically.
Accepts an Array, a list-delimited String, an existing Set, a QueryColumn, an XML node, a bounded Range, or any value castable to a Set. When the value is already of the requested variant it is returned as-is; otherwise a new Set of the specified variant is created and populated.
Method Signature
ToSet(value=[any], type=[string], delimiter=[string])Arguments
value
any
true
The value to convert. Accepts Array, Set, list-delimited String, QueryColumn, XML, Range, etc.
type
string
false
The backing variant: "default" / "hash" (HashSet), "linked" / "ordered" (LinkedHashSet), or "sorted" / "tree" (TreeSet). Defaults to "default".
default
delimiter
string
false
When {@code value} is a String, the list delimiter to split on. Defaults to {@code ","}.
,
Examples
Convert an array to a Set
Deduplicates the array elements and returns a BoxSet.
s = [ 1, 2, 2, 3 ].toSet();
writeOutput( s.size() );
Result: 3
Convert to a linked (insertion-ordered) Set
Result: [c, a, b]
Convert to a sorted Set
Result: [1, 3, 5, 9]
Related
Last updated
Was this helpful?
