Collections

Collections in Apex can be lists, sets, or maps.

There is no limit on the number of items a collection can hold. However, there is a general limit on heap size.

Note

  • Lists

    A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

  • Sets

    A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

  • Maps

    A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.

  • Parameterized Typing

    Apex, in general, is a statically-typed programming language, which means users must specify the data type for a variable before that variable can be used.

See Also