+ Start a Discussion
SFAdmin5SFAdmin5 

list method

What does the "-1" here mean, where leadCalls is a List:

 

(leadCalls.get(leadCalls.size() - 1)

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This code is accessing the final element in a array (list).

 

Arrays are index origin 0, so if the size of the array is 10, the last element is actually at position 9 (because the first element is at position 0).

All Answers

bob_buzzardbob_buzzard

This code is accessing the final element in a array (list).

 

Arrays are index origin 0, so if the size of the array is 10, the last element is actually at position 9 (because the first element is at position 0).

This was selected as the best answer
OyeCodeOyeCode
A list is an ordered collection of typed primitives, sObjects, user-defined objects, Apex objects or collections that are distinguished by their indices. For example, the following table is a visual representation of a list of Strings:
Index 0 Index 1 Index 2 Index 3 Index 4 Index 5
'Red' 'Orange' 'Yellow' 'Green' 'Blue' 'Purple'
The index position of the first element in a list is always 0.
Because lists can contain any collection, they can be nested within one another and become multidimensional. For example, you can have a list of lists of sets of Integers. A list can contain up to four levels of nested collections inside it.


Read more in here though bob explained it beautifully but here is official link

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_collections_lists.htm