+ Start a Discussion
Preetham ThummalaPreetham Thummala 

Underlying data structure

What is the underlying structure in List and Set?
NagaNaga (Salesforce Developers) 
Hi Preetham,

When we do a query in Salesforce we get back a list. A list is defined in Apex as being an ordered collection of items that are distinguished by their indices. The list is a very helpful data structure and is very easy to work with.

Here is an example in the link below where we query out values into a list, loop through them and then do an update.

http://www.sundoginteractive.com/sunblog/posts/apex-why-maps-are-your-friend

Best Regards
Naga Kiran
Vivek DeshmaneVivek Deshmane

Hi Preetham,

Lists are ordered, you can get specific elements of your List by the element’s index, or, List position. 
Indexes start at zero and go all the way up to number of records in your list, minus one! So if you wanted to get specific elements of your List, you could do this using brackets.

Sets  basically lists however they’re unordered and don’t allow any duplicate values.
Please refer following links for more detail.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_sets.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm

Regards,
-Vivek Deshmane