Ahmmm... i think those are very very short descriptions about what you can do with a list :o
First of all: yes, with an array you always know the position of that object, number or whatever you keep in there... but a big inconvenient is the way you move in the positions of an array, with a list you have a lot of methods to make the size dynamic (this is something you cant do with an array), also with a list you never get empty positions (you just add or remove items and thats it!), you can find an object without implementing a method yourself because the list already has it (it is named find, of course), and you can loop it with a for-each loop.
In the other hand, and talking about pros and cons: a list definitely needs more memory... but you have to consider also the kind of data you're gonna work with, it is not just a matter of habit.
Give as an example of method which can NOT be invoked on ARRAY. As you see from me example above there is no such method which you can invoke on Lis tand can not on array.
one more difference I read on https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm
String[] colors = new List<String>(); String[] colors = new String[1];
Even though the size of the previous String array is defined as one element (the number between the brackets in new String[1]), lists are elastic and can grow as needed provided that you use the List add method to add new elements. For example, you can add two or more elements to the colors list. But if you’re using square brackets to add an element to a list, the list behaves like an array and isn’t elastic, that is, you won’t be allowed to add more elements than the declared array size.
A "array notation" of a list using [] can only be one dimensional
All Answers
With an array you always know where you're and a list you don't
As I understand from documentation no difference. It's just a mater of habit.
This is what I am getting, I guess you are right.
Thanks
Ahmmm... i think those are very very short descriptions about what you can do with a list :o
First of all: yes, with an array you always know the position of that object, number or whatever you keep in there... but a big inconvenient is the way you move in the positions of an array, with a list you have a lot of methods to make the size dynamic (this is something you cant do with an array), also with a list you never get empty positions (you just add or remove items and thats it!), you can find an object without implementing a method yourself because the list already has it (it is named find, of course), and you can loop it with a for-each loop.
In the other hand, and talking about pros and cons: a list definitely needs more memory... but you have to consider also the kind of data you're gonna work with, it is not just a matter of habit.
No man,
You are wrong.
Give as an example of method which can NOT be invoked on ARRAY. As you see from me example above there is no such method which you can invoke on Lis tand can not on array.
A "array notation" of a list using [] can only be one dimensional
You are absolutely right.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm
String[] colors = new List<String>();
String[] colors = new String[1];
Even though the size of the previous String array is defined as one element (the number between the brackets in new String[1]), lists are elastic and can grow as needed provided that you use the List add method to add new elements. For example, you can add two or more elements to the colors list. But if you’re using square brackets to add an element to a list, the list behaves like an array and isn’t elastic, that is, you won’t be allowed to add more elements than the declared array size.