Difference between List, Set and Map in Salesforce

List:

  • List is a collection of elements, Such as primitive data types (String, Integer, Date, etc), user defined objects, sObjects, Apex objects or other collections (can be multidimensional up to 5 levels).
  • List allows duplicate values.
  • List index position starts from zero.

Set:

  • Set is a collection of unique, unordered elements.
  • It can contain primitive data types (String, Integer, Date, etc) or sObjects.
  • Set allows unique values.

Map:

  • Map is a collection of key-value pair.
  • Keys can be any primitive data types (String, Integer, Date, etc) while values can include primitives, Apex objects, sObjects and other collections.
  • Map allows duplicate values, but each key must be unique.

Leave a Reply