Is the array-object in Salesforce really an array, or is it a list "disguised" as an array?

Specifically: Is the access of myArray[3] really random (="quick") or does the runtime need to iterate over the first 3 elements to finally find myArray[3] like it would in a normal list?

So is the access of the n-th element of an array faster than the access of the n-th element of a list? Or is the access time equal for arrays and lists?

More specifically: Is the array in Salesforce implemented as a linked list? That would mean that the complexity of myArray[3] is O(n), which would be not typical for an array. Therefore I don't believe that this is not the case, but as of yet I didn't find an exact definition. (I'm a newbie though, and I may have missed out important documentation)


3 Answers 3


It is very likely - a test would confirm - that Apex uses an array-backed list for its lists and a quick check of the typical source code or typical documentation:

The size, isEmpty, get, set, iterator, and listIterator operations run in constant time.

indicates that access speed at the various indexes is constant for such a list.


In Salesforce, Lists and Arrays are treated as same. e.g. Below two statements are equivalent:

String[] colors = new List< String >();


List< String > colors = new List< String >();

Please refer to this for more detailed explanation.


In Apex, there are no arrays, only lists. If you look in the Apex Developers' Guide, you will find both the Java array syntax and list syntax under the section for working with lists.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .