This course is currently a work in progress. Please join the waitlist to receive regular updates.

Set in apex

What is a Set?

A set is a collection of unique elements with no duplicate values. Set automatically deduplicate items and it is ideal when data uniqueness is required.

How to declare a set?

You can declare a set using the Set <datatype>. Following is an example of an empty Set of strings.

Loading...

In the above example:

  • The keyword Set is used to declare a set which can hold string values.
  • The variable name names can be used to operate (add/remove..etc) on the set.
  • Thenames set contain no values.