Whatever message this page gives is out now! Go check it out!

symmetricDifference

Last update:
May 18, 2026
Returns elements in either set but not in both.

Description

Returns the symmetric difference of two sets. The function returns elements that are present in either set, but not in both.

Returns

A new Set.

Category

ColdFusion Set member methods

Function syntax

set.symmetricDifference(otherSet)

Parameters

ParameterDescription
otherSetAnother Set.

See also

Example

The following example uses this API in cfscript (syntax: set.symmetricDifference(otherSet)).

<cfscript>
    setA = setNew();
    setA.add(1);
    setA.add(2);
    setA.add(3);

    setB = setNew();
    setB.add(2);
    setB.add(3);
    setB.add(4);

    symmetricSet = setA.symmetricDifference(setB);
    // 1 and 4 are only on one side; 2 and 3 are in both → excluded
    writeOutput(symmetricSet.size()); // 2
</cfscript>
      

Real-world example

Compare yesterday versus today user-ID snapshots to find accounts added or removed.

<cfscript>
    /**
    * Symmetric difference highlights IDs that appear in only one snapshot
    * (new or removed compared to pairwise “in both” sets).
    */
    yesterday = setNew();
    yesterday.add("user1");
    yesterday.add("user2");

    today = setNew();
    today.add("user2");
    today.add("user3");

    changed = yesterday.symmetricDifference(today);
    // user1 only yesterday, user3 only today
    writeOutput(changed.size()); // 2
</cfscript> 
      

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page