function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ashish jadhav 9ashish jadhav 9 

how to decide when to use list and when to use set?

please explain when should I go for set and list?
Piyush Kumar 58Piyush Kumar 58
Hello Ashish,

List and Set 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>

Find below link for Detailed explanation regarding collections