Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to convert a list of Strings to an array of strings.

I do:

// ccEmails is the list of Strings
String [] emailsAsArray = new String [ccEmails.size()];
Integer i = 0;
for (String singleCCEmail: ccEmails) {
    emailsAsArray[i++] = singleCCEmail;

This seems a horrible cumbersome way. Is there a better way?

share|improve this question
Are you talking Apex? Java? C#? If Apex, there is no such thing as Array. It is all list, even though the syntax looks like array. – Peter Feb 7 '13 at 15:32
@Peter Thanks. I am talking Apex as per tag. – dublintech Feb 7 '13 at 15:39
sorry...should have noticed. :-) – Peter Feb 7 '13 at 15:40
up vote 19 down vote accepted

There is no such thing as array in Apex.

The creators of Apex decided that they would support two different but completely compatible syntax conventions for the same underlying object: List. One looks like array, the other looks like List, but they are both List.

I could literally do this:

List<String> myStrings = new String[2];

myStrings[0] = 'this'; 
myStrings.add('the other');


This (ugly and unreadable as it is) compiles and runs successfully.

share|improve this answer
great answer thanks so much. – dublintech Feb 7 '13 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.