Using the addAll(listToAdd)
method we can append an entire list to another list, like so:
List<String> earlyOptyStages = new List<String>(); earlyOptyStages.add('Prospecting'); earlyOptyStages.add('Qualification'); earlyOptyStages.add('Needs Analysis'); List<String> closedOptyStages = new List<String>(); closedOptyStages.add('Closed Won'); closedOptyStages.add('Closed List'); List<String> allStages = new List<String>(); allStages.addAll(earlyOptyStages); allStages.addAll(closedOptyStages);
or alternatively, add it like this:
List<String> allStages = new List<String>(earlyOptyStages); allStages.addAll(closedOptyStages);
With Apex, as you've probably figured out by now, there are a lot of ways to do the same thing. Sometimes there are performance considerations; other times they're just stylistic preferences.