Collection | Set

 

Set Collection Class:

ü Set is an unordered collection, which doesn’t preserve the insertion order.

ü Set collection will arrange the elements inside the collection in sorting order by default.

ü Set collection allows to store PRIMITIVE Type elements, SObject Type, Apex Type, Collection Type and user defined type elements.

ü Set collection supports the Dynamic memory allocation

ü Hence the memory size can grow / shrink at runtime.

ü Set collection doesn’t allow the Duplicate elements. Upon adding the new elements, it will maintain the uniqueness with the help of BINARY COMPARISON.

ü Set collection provides a set of readymade methods, to manage the elements inside the collection.


      Syntax:

Set <Datatype> <objectName> = new Set<Datatype> ();

Example:

 Set<integer> customer Codes = new Set<integer> ();

Set<String> CountryNames = new Set<String> ();

Set<Id> recordIds = new Set<Id> ();

Set<Account> accountsSet = new Set<Account> ();


Post a Comment

0 Comments