How many Type Collection in Salesforce?
Ans:-
3 types
a) Lists
b) Set
c) Map
What is list ?
Ans:-
A list is an ordered collection of typed primitives, sObjects, user-defined
objects, Apex objects or collections that are distinguishedby their indices.The
index position of the first element in a list is always 0.
Example:-
List<String>mylist = new List<String>();
What is Set ?
Ans:- A set is an
unordered collection of primitives or sObjects that do not contain any
duplicate elements.
To access elements in
a set, use the system methods provided by Apex.
Example:-
Set<Integer> st = new Set<Integer>
(); // Define a new set
st.add (1); // Add an element to the set
st.remove
(1); // Remove the element from the set
What is Map?
Ans:- 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.
To declare a map, use the Map keyword
followed by the data types of the key and the value within <> characters.
Example :-
Map<String, String>country_currencies = new
Map<String, String>();
Map<ID, Set<String>> m = new
Map<ID, Set<String>>();
Map<ID, Map<ID, Account[]>> m2 = new
Map<ID, Map<ID, Account[]>>();
No comments:
Post a Comment