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. EX: Map<id,Account> holds id and account record with that id
Find below link for Detailed explanation regarding collections http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections.htm
List, Set and map are collections used in apex. These are useful when governor limits are reached to a limit while querying records inside the for loop. Instaed of writing query and reaching the limit we can use set to get ID's of the records and iterate through it.
Map: It is a collection which stores key,value pairs where key is unique and it can be of any data type like sobject,integer,string etc.
Set: It is a unique collection of values which does not contain duplicates.
List: It is a collection of records which is an ordered collection. The main diff between list and set is list contains duplicate values but set doesn't contain any duplicate values.
Collections work somewhat like arrays, except their size can change dynamically, and they have more advanced behaviors and easier access methods than arrays. Data collections are simply groupings of any data type. You’ll use data collections often because they go hand in hand with SOQL. The reason why Lists are so important is because the output of every SOQL query is a List. The unique aspect of Lists is that they are ordered – had we ordered our SOQL query by Email address, this structure would be preserved in our variable! I would like to share a video link https://www.youtube.com/watch?v=ksshmekZ6V8 which will benefit you. Set: A set is a collection of unique, unordered elements. It can contain primitive data types (String, Integer, Date, etc) or objects. If you need ordered elements use a List instead. You typically see Sets used to store collections of IDs that you want to use in a SOQL query. Map: It is a collection of key-value pairs. Keys can be any primitive data type while values can include primitives, Apex objects, objects and other collections. Use a map when you want to quickly find something by a key. Each key must be unique but you can have duplicate values in your Map.
List : You can perform DML operations. It is ordered and have duplicates Sets : Sets we use actually for the unique values. You cannot perform DML with Sets.
Map 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. For example, the following table represents a map of countries and currencies
Hi Bhupathi, The collection is the type variables which can store multiple numbers of records. It can increase and decrease dynamically. There are 3 types of collection: a.List Collection: List can contain any number of records of primitive, collections, sObjects, user defined and built in Apex type. This is one of the most important type of collection and also, it has some system methods which have been tailored specifically to use with List. List index always starts with 0. This is synonymous to the array in Java. A list should be declared with the keyword 'List'. Example-> Below is the list which contains the List of a primitive data type (string), that is the list of cities. List<string> ListOfCities = new List<string>(); System.debug('Value Of ListOfCities'+ListOfCities); b.Set Collection: A Set is a collection type which contains multiple number of unordered unique records. A Set cannot have duplicate records. Like Lists, Sets can be nested. Example-> We will be defining the set of products which company is selling. Set<string> ProductSet = new Set<string>{'Phenol', 'Benzene', 'H2SO4'}; System.debug('Value of ProductSet'+ProductSet); c.Map Collection. It is a key value pair which contains the unique key for each value. Both key and value can be of any data type. Example-> The following example represents the map of the Product Name with the Product code. Map<string, string> ProductCodeToProductName = new Map<string, string> {'1000'=>'HCL', '1001'=>'H2SO4'}; System.debug('value of ProductCodeToProductName'+ProductCodeToProductName);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too. Thanks, Ajay Dubedi
Collections is a type of variable that can store multiple numbers of records. For example, a List can store multiple numbers of Account object's records.
Lists The list can contain any number of records of primitive, collections, sObjects, user-defined and built-in Apex type. This is one of the most important types of collection and also, it has some system methods which have been tailored specifically to use with List. The list index always starts with 0. This is synonymous with the array in Java. A list should be declared with the keyword 'List'.
Sets A Set is a collection type that contains multiple numbers of unordered unique records. A Set cannot have duplicate records. Like Lists, Sets can be nested.
Maps It is a key-value pair that contains the unique key for each value. Both keys and values can be of any data type.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
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.
EX: Map<id,Account> holds id and account record with that id
Find below link for Detailed explanation regarding collections
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections.htm
List, Set and map are collections used in apex. These are useful when governor limits are reached to a limit while querying records inside the for loop. Instaed of writing query and reaching the limit we can use set to get ID's of the records and iterate through it.
Map: It is a collection which stores key,value pairs where key is unique and it can be of any data type like sobject,integer,string etc.
Set: It is a unique collection of values which does not contain duplicates.
List: It is a collection of records which is an ordered collection. The main diff between list and set is list contains duplicate values but set doesn't contain any duplicate values.
Regards,
Anuj
Data collections are simply groupings of any data type. You’ll use data collections often because they go hand in hand with SOQL.
The reason why Lists are so important is because the output of every SOQL query is a List. The unique aspect of Lists is that they are ordered – had we ordered our SOQL query by Email address, this structure would be preserved in our variable! I would like to share a video link https://www.youtube.com/watch?v=ksshmekZ6V8 which will benefit you.
Set: A set is a collection of unique, unordered elements. It can contain primitive data types (String, Integer, Date, etc) or objects. If you need ordered elements use a List instead. You typically see Sets used to store collections of IDs that you want to use in a SOQL query.
Map: It is a collection of key-value pairs. Keys can be any primitive data type while values can include primitives, Apex objects, objects and other collections. Use a map when you want to quickly find something by a key. Each key must be unique but you can have duplicate values in your Map.
Hello
List :
You can perform DML operations.
It is ordered and have duplicates
Sets :
Sets we use actually for the unique values.
You cannot perform DML with Sets.
Map
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. For example, the following table represents a map of countries and currencies
The collection is the type variables which can store multiple numbers of records. It can increase and decrease dynamically.
There are 3 types of collection:
a.List Collection:
List can contain any number of records of primitive, collections, sObjects, user defined and built in Apex type. This is one of the most important type of collection and also, it has some system methods which have been tailored specifically to use with List. List index always starts with 0. This is synonymous to the array in Java. A list should be declared with the keyword 'List'.
Example->
Below is the list which contains the List of a primitive data type (string), that is the list of cities.
List<string> ListOfCities = new List<string>();
System.debug('Value Of ListOfCities'+ListOfCities);
b.Set Collection:
A Set is a collection type which contains multiple number of unordered unique records. A Set cannot have duplicate records. Like Lists, Sets can be nested.
Example->
We will be defining the set of products which company is selling.
Set<string> ProductSet = new Set<string>{'Phenol', 'Benzene', 'H2SO4'};
System.debug('Value of ProductSet'+ProductSet);
c.Map Collection.
It is a key value pair which contains the unique key for each value. Both key and value can be of any data type.
Example->
The following example represents the map of the Product Name with the Product code.
Map<string, string> ProductCodeToProductName = new Map<string, string>
{'1000'=>'HCL', '1001'=>'H2SO4'};
System.debug('value of ProductCodeToProductName'+ProductCodeToProductName);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Collections are very useful when your dealing with bulk records
Below code helps to avoid duplicate email in the object during inserstion or Upgrade .
Collections plays vital role in the below code ,Which makes developer an easy way to write code .
Please use the below post for Detailed exaplanation with usage of collection.
Collections with scenario explanation (https://salessforcehacks.blogspot.com/2020/01/collections-in-salesforce-list-set-map.html)
Let us know if you require any further details .
Collections is a type of variable that can store multiple numbers of records. For example, a List can store multiple numbers of Account object's records.
Lists
The list can contain any number of records of primitive, collections, sObjects, user-defined and built-in Apex type. This is one of the most important types of collection and also, it has some system methods which have been tailored specifically to use with List. The list index always starts with 0. This is synonymous with the array in Java. A list should be declared with the keyword 'List'.
Sets
A Set is a collection type that contains multiple numbers of unordered unique records. A Set cannot have duplicate records. Like Lists, Sets can be nested.
Maps
It is a key-value pair that contains the unique key for each value. Both keys and values can be of any data type.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com