0

When/where is it appropriate to use them?

Is "put" only used for collection?

1 Answer 1

7

The 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');

You must log in to answer this question.

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