-3

I have a list like that:

List l = new List();

l.add('a');

l.add('b');

l.add('1');

l.add('2');

l.add('3');

How can I add all those values at once without using so many add methods? In Java we can do List list = new ArrayList<>(Arrays.asList("a", "b", "1", 2", "3"));

Can we use something similar in Apex?

1 Answer 1

8

You can initialize list with your items:

List<String> l = new List<String>{'a', 'b', 'c', 'etc'};

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