List : A list is an ordered collection so use list when you want to identify list element based on Index Number. List (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
for Collection(List,Map,Set) follow this :- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections.htm
Learn more about Collections (list, set, map) using the below Apex Developer Guide
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections.htm
Happy learning!
Hope this helps you!
Thanks,
Rakesh
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. List (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
for Collection(List,Map,Set) follow this :- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections.htm
Apex Developer Guide :-https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm
Please select this answer as best if you find it helpful.
Thank You,
Ajay Dubedi
Below post can provide you whole idea of collections with hands on practice examples .
Collections In Salesforce (https://salessforcehacks.blogspot.com/2020/01/collections-in-salesforce-list-set-map.html)