SetNew
Create a new empty Set, optionally pre-seeded from an existing collection.
The backing variant (hash, linked, or sorted) and case-sensitivity can be configured. When no seed is provided, an empty Set of the requested variant is returned.
Method Signature
SetNew(type=[string], values=[any], caseSensitive=[boolean], isSynchronized=[boolean])Arguments
type
string
false
The backing variant: "default" / "hash" (HashSet), "linked" / "ordered" (LinkedHashSet, preserves insertion order), or "sorted" / "tree" (TreeSet, natural ordering).
default
values
any
false
An optional seed collection (Array, Set, or anything castable to a Set). Its elements are deduplicated into the new set. A single non-collection value seeds a one-element set.
caseSensitive
boolean
false
Whether string element comparisons are case-sensitive. Defaults to false.
false
isSynchronized
boolean
false
Whether the set should be thread-safe (synchronized). Default is true.
true
Examples
Create an empty default Set
Creates a new empty hash-based Set (no ordering, fastest lookup).
s = setNew();
writeOutput( s.size() );
Result: 0
Create a linked (insertion-ordered) Set seeded with values
Duplicate values are automatically removed.
Result: [c, a, b]
Create a sorted Set
Elements are kept in natural ascending order at all times.
Result: [1, 3, 5, 9]
Create a case-sensitive Set
By default Sets are case-insensitive. Pass caseSensitive=true to treat different cases as distinct elements.
Result: 3
Default behavior is case-insensitive
Result: 1
Create an unsynchronized (non-thread-safe) Set
Pass isSynchronized=false for a faster single-threaded set that skips locking overhead.
Result: 3
Related
Last updated
Was this helpful?
