Sunday, November 7, 2021

Difference between Container, List, Map and Set

 Containers:

Containers are dynamic and have no limits. They can contain elements of

almost all data types: boolean, integer, real, date, string, container,

arrays, tables, and extended data types. However, objects may not be stored

in containers.

Containers in AX are used very often. It’s easy to work with them. But…

data in containers are stored sequentially and thus retrieved sequentially.

This means that containers provide slower data access if you are working with

_large numbers_ of records. In case of large numbers of records use temporary

tables.


List:

Lists are structures that may contain any number of elements that are

accessed sequentially. Lists may contain values of any X++ type. All the

values in the list must be of __the same__(this is the main difference

between lists and containers) type, given in the creation of the list. The

implementation of lists is such that the traversal of the list elements is __very

fast.

Take a look for example at the class Dialog addControl() method.

Their controls are stored in ctrls List.


Map:

A map is a data type that associates one (key) value with another value [An

analog – a small table in memory with two fields: Keys, Values]. Both the key

and value values may be of any valid X++ type, including objects. The types

of the key and the value are given in the declaration of the map. The

implementation of maps is such that access to the values is _very fast_.

Don’t confuse map X++ types with Map objects in AOT, which are used for

mapping tables with similar structures of fields


Set:

The functionality of Sets is similar to the list.  A Set is just an unordered list of items, while a list of items held by a Map

are indexed via a key.

Take look at

\Classes\sysLabel\LabelModuleId()