function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Divya Gupta 11Divya Gupta 11 

Create an Apex class that returns an array (or list) of strings.-Error

public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n){
        String[] test = new List<String>();
         for(Integer i=0;i<n;i++){
            test.add('Test'+i);
            System.debug(test[i]);
         }


Getting an error "Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
        return test;
  }
   
}
Siddharth ManiSiddharth Mani
I guess there has to be a space after Test and the number getting printed after it. try changing your add statement as below:
            test.add('Test '+i);
Divya Gupta 11Divya Gupta 11
Yes, Space was the problem. Thank you, it's solved now.