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
Thomas MillerThomas Miller 

Returning an Array of Strings (1st Trailhead Programmatic Tutorial)

Thought this challenge was pretty straight forward, but I'm not sure what to do based on the error message; here is the challenge copy&paste:

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.




Here's my Apex Class:


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

And here's the error message upon checking that class upon:

Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.
Best Answer chosen by Thomas Miller
Suneel#8Suneel#8
You should have a space folloring Test like below

s.add('Test ' + i);

Kindly mark this question as solved if it fixes your code

All Answers

Suneel#8Suneel#8
You should have a space folloring Test like below

s.add('Test ' + i);

Kindly mark this question as solved if it fixes your code
This was selected as the best answer
SattibabuSattibabu
I had the similar issue and now it's been resolved with this post. Thanks Thomas and Suneel for your assistance.