Activity Forums Salesforce® Discussions When should I use Lists and Maps and Sets in Apex?

  • Himanshu

    Member
    August 2, 2016 at 1:26 pm

    Hi Pranav,

    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

    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

    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

    Hope this helps you.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos