A Set is used for the storage and retrieval of data from a collection in which the
members are unique. The values of the members serve as the key according to
which the data is automatically ordered. Thus, it differs from a List collection
class where the members are placed into a specific position, and not ordered
automatically by their value.
Set members may be of any X++ type. All members in the set must have the
same type.
When a value that is already stored in the set is added again, it is ignored and
does not increase the number of members in the set.
static void Sets(Args _args)
{
Set setOne;
Set setTwo;
SetEnumerator enumerator;
Int value;
//insert data into sets
setOne = new Set(types::Integer);
setOne.add(1);
setOne.add(2);
setOne.add(3);
setTwo = new Set(Types::Integer);
setTwo.add(3);
setTwo.add(4);
setTwo.add(5);
enumerator = setOne.getEnumerator();
while (enumerator.moveNext())
{
value = enumerator.current();
//comparing setone & settwo
if (setTwo.in(value))
{
//deleting same value as setone in settwo
setTwo.remove(value);
}
}
//print no of elements in sets
info(strFmt('Set one element is : %1', setOne.elements()));
info(strFmt('Set two element is : %1', setTwo.elements()));
//print set one elements
enumerator = setOne.getEnumerator();
while (enumerator.moveNext())
{
setPrefix(strFmt('%1', 'Set one'));
info(strFmt('%1', enumerator.current()));
}
//print set two elements
enumerator = setTwo.getEnumerator();
while (enumerator.moveNext())
{
setPrefix(strFmt('%1', 'Set two'));
info(strFmt('%1', enumerator.current()));
}
}