You need to sign in to do that
Don't have an account?

Use of Maps in Apex
Hi All,
Any one can please explain what is the use/significance of Map(s) in Apex. And what can do with maps & can not do without maps.
Thanks a ton in advance !
SK.
You need to sign in to do that
Don't have an account?
Hi All,
Any one can please explain what is the use/significance of Map(s) in Apex. And what can do with maps & can not do without maps.
Thanks a ton in advance !
SK.
Hi SK,
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.
By using maps you can get the values of corresponding key without iterating.
For example
Account myAcct=new Account(); //Define a new account
Map<Integer, Account> m = new Map<Integer, Account>(); // Define a new map
m.put(1, myAcct); // Insert a new key-value pair in the map
System.assert(!m.containsKey(3)); // Assert that the map contains a key
Account a = m.get(1);
Using this way you are reducing the number of executable lines.
If you use List, you have to iterate over the list.
All Answers
Hi SK,
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.
By using maps you can get the values of corresponding key without iterating.
For example
Account myAcct=new Account(); //Define a new account
Map<Integer, Account> m = new Map<Integer, Account>(); // Define a new map
m.put(1, myAcct); // Insert a new key-value pair in the map
System.assert(!m.containsKey(3)); // Assert that the map contains a key
Account a = m.get(1);
Using this way you are reducing the number of executable lines.
If you use List, you have to iterate over the list.
Thank you very much for the explaination.
SK