+ Start a Discussion
Newbie999Newbie999 

Hi, Can someone please explain why in some programs they have used Account[] everywhere?

Hi, Can someone please explain why in some programs they have used Account[] everywhere and somewhere they have created lists and then written SOQL on accounts?

TIA
Best Answer chosen by Newbie999
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

An array notation of a list using [] can only be one dimensional but List can be multi-dimensional i.e., list of lists. 

When using one-dimensional lists of primitives or objects, you can also use more traditional array notation to declare and reference list elements. For example, you can declare a one-dimensional list of primitives or objects by following the data type name with the [] characters.


In short, you can use the array notation to declare a list. All list methods can be used with it. The main difference is that Lists can be multidimensional.


Please refer to the below link which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm?search_text=array

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Greg HGreg H
Probably different developers. It's two different ways to create a list of Account.
-greg
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

An array notation of a list using [] can only be one dimensional but List can be multi-dimensional i.e., list of lists. 

When using one-dimensional lists of primitives or objects, you can also use more traditional array notation to declare and reference list elements. For example, you can declare a one-dimensional list of primitives or objects by following the data type name with the [] characters.


In short, you can use the array notation to declare a list. All list methods can be used with it. The main difference is that Lists can be multidimensional.


Please refer to the below link which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm?search_text=array

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer