Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
1  
@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

1 Answer 1

up vote 14 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.set(1,'that');
myStrings.add('the other');

System.debug(myStrings);  

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

 
discard

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.