You need to sign in to do that
Don't have an account?
Prerna Bhalla
Difference between both list = list , list.addAll(list), list.add(listvalue)
list<Account> stringList;
list<Account> stringList1 = new list<Account>();
list<Account> stringList2 = new list<Account>();
list<Account> stringList3 = new list<Account>();
public listTestClass() {
stringList = new list<Account>();
stringList= [select id, name, (select id, name from Contacts) from Account limit 2];
// scenerio 1
stringList1 = stringList;
//scenerio 2
for(Account a : stringList ) {
stringList2.add(a);
}
//scenerio 3
stringList3.addAll(stringList);
list<Account> stringList1 = new list<Account>();
list<Account> stringList2 = new list<Account>();
list<Account> stringList3 = new list<Account>();
public listTestClass() {
stringList = new list<Account>();
stringList= [select id, name, (select id, name from Contacts) from Account limit 2];
// scenerio 1
stringList1 = stringList;
//scenerio 2
for(Account a : stringList ) {
stringList2.add(a);
}
//scenerio 3
stringList3.addAll(stringList);
That is Really a nice Scenerio and i know what u want to know ......
Scenerio 1----
Lets suppose StringList have values are {a,b}
Take one more StringListnew which have value are {a,b,c,d,e} ok
StringList1=StringList;
then StringList1 have value {a,b}
again if you do
StringList1=StringListnew;
then StringList1 have value {a,b,c,d,e}
"Note" -- in this case common values are not added
Scenerio 3---
Do same thing here and in this case
"Note"--In this case common values are added so value will be {a,b,a,b,c,d,e}
Scenerio 2--
here you are iterating the value so it will be same like Scenerio-3
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
i did some change in your program and use some debug to show you the values and posted with ScreenShot
Note --------I hope this will helpfull Please mark as best answer ....
Thank you
Avaneesh Singh
If still any confusion Please Let me know and if this was helpfull don't forget to mark as best answer
Thank you
Avaneesh Singh