Activity › Forums › Salesforce® Discussions › What is the difference between List, Map and Set in Salesforce?
Tagged: Key Value Pairs, List, Map, Ordered Collection, Set in Salesforce, SObjects
-
What is the difference between List, Map and Set in Salesforce?
Posted by Pooja on February 7, 2020 at 2:17 PMWhat is the Difference Between List, Map and Set in Salesforce?
Anjali replied 6 years, 4 months ago 5 Members · 4 Replies -
4 Replies
-
The list is a type of ordered collection that maintains the elements in insertion order, Set is a type of unordered collection and Map is a collection of key-value pairs.
-
This reply was modified 6 years, 3 months ago by
Forcetalks.
-
This reply was modified 6 years, 3 months ago by
- [adinserter block='9']
-
Hi Pooja,
List- A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects.
Set– A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of any data type—primitive types, collections, sObjects.
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.
-
List: This is the most common collection data type. It includes a sort() method, so we use a list whenever we need something to be ordered.
Set: Sets are unordered collection and It enforces uniqueness (it means, used to prevent duplicates in our code).
Map: It is a collection that consists of key-value pairs.
- Keys – It behaves like a set (which is unique).
- Values – It behaves like a list.
-
This reply was modified 6 years, 3 months ago by
Forcetalks.
-
This reply was modified 6 years, 3 months ago by
Forcetalks.
-
List– it is an ordered collection.
Set– it is an unordered collection.
Map– it is a collection of key-value pairs.
-
This reply was modified 6 years, 3 months ago by
Forcetalks.
-
This reply was modified 6 years, 3 months ago by
Log In to reply.