List : A list is an ordered collection so use list when you want to identify list element based on Index Number.(Lsit can contain Duplicates) EX: List<account>
Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements. So, use set if you want to make sure that your collection should not contain Duplicates. EX: Set<account>
Map: A map is a collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject, collection type or an Apex object. For example, the following table represents a map of countries and currencies
List : A list is an ordered collection so use list when you want to identify list element based on Index Number.(Lsit can contain Duplicates) EX: List<account>
Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements. So, use set if you want to make sure that your collection should not contain Duplicates. EX: Set<account>
Map: A map is a collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject, collection type or an Apex object. For example, the following table represents a map of countries and currencies
Map<String, Lead> and let us assume that string is email (one of the field in lead)..what happens when we use that code...like email will have a relation with lead? (as we all know that email is already related with the lead)
how do we pronounce it clearly...like whether lead has a relation with string or mapped with string...
List-You can use list when you are dealing with bulk records.
Set-You can use set when you require to deal with Unique records (Set is similar to List collection type ,The only difference is Set does not allow duplicate values ).
Map-Map can help you when you are dealing with parent-child executions .
Hi,
List,Set,Map are called collections in Apex:
List : A list is an ordered collection
so use list when you want to identify list element based on Index Number.(Lsit can contain Duplicates)
EX: List<account>
Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements.
So, use set if you want to make sure that your collection should not contain Duplicates.
EX: Set<account>
Map: A map is a collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject, collection type or an Apex object. For example, the following table represents a map of countries and currencies
Find below link for Detailed explanation regarding collections
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections.htm
:
All Answers
Hi,
List,Set,Map are called collections in Apex:
List : A list is an ordered collection
so use list when you want to identify list element based on Index Number.(Lsit can contain Duplicates)
EX: List<account>
Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements.
So, use set if you want to make sure that your collection should not contain Duplicates.
EX: Set<account>
Map: A map is a collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject, collection type or an Apex object. For example, the following table represents a map of countries and currencies
Find below link for Detailed explanation regarding collections
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections.htm
:
Thanks HariDinesh
If I have
Map<String, Lead> and let us assume that string is email (one of the field in lead)..what happens when we use that code...like email will have a relation with lead? (as we all know that email is already related with the lead)
how do we pronounce it clearly...like whether lead has a relation with string or mapped with string...
Hi,,
In Map, Generally we called as Key-Value pair.
As in your Example: Map<email,Lead>
Then we called as : The value of Email1 is Lead1
and
Lead1 has Key as Email1
So here Lead1 is 1st record..thats what you are telling? please let me know if I'm worng
So if 1st email is mapped with 1st record, 2nd email is mapped with 2nd record and so on..
Please let me know whether we are on the same page.
Yes,
Exactly..
i think this can help you too...though like sharing
http://share-salesforce.blogspot.in/2013/05/sfdc-data-collections-listsetmap.html
List-You can use list when you are dealing with bulk records.
Set-You can use set when you require to deal with Unique records (Set is similar to List collection type ,The only difference is Set does not allow duplicate values ).
Map-Map can help you when you are dealing with parent-child executions .
Please find the below post for basic to advacned examples.
List Vs Set Vs Map InSalesforce (https://salessforcehacks.blogspot.com/2020/01/collections-in-salesforce-list-set-map.html)