What is a Map in apex salesforce?

Map is the one of the best collection type in apex programming language. It's more powerfull and more flexible collection in apex. It stores data in the form of Key and Value pairs. The Key and value in a map can be user-defined data types. Keys can only be Primitive data type, and Values can be primitive, sobject, apex class and any other collection type.(i.e list or set). Keys can't be Duplicates, values can. 

Most Powerful Apex Collection Map

Now we are going to show you some common map methods used in apex language. below is the basic syntax of the map.

Map <key, value> mapname = new Map<key, value>();
Map <Key_Datatype, Value_Datatype> simpleMap = new Map <Key_Datatype, Value_Datatype> ();

Define Simple Map

Defining a simple map of Key is Integer and Value is String.
Map <Integer, String> simpleMap = new Map <Integer, String> ();

Labels:
Map
Join the conversation