When/where is it appropriate to use them?
Is "put" only used for collection?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityThe add
method is for List
or Set
. The put
method is for Map
.
List<String> collection1 = new List<String>();
collection1.add('foo');
Set<String> collection2 = new Set<String>();
collection2.add('foo');
Map<String, String> collection3 = new Map<String, String>();
collection3.put('foo', 'bar');