You need to sign in to do that
Don't have an account?
Bhavesh Jain 41
Trailhead challenge:Create an Apex class that returns an array (or list) of strings.
Below is my code:
public class StringArraytest
{
public static List<string> generateStringArray(integer n)
{
integer i=5;
List<string> str= new List<string>();
for(i=0;i<n;i++)
{
str.add('test '+i);
system.debug(str[i]);
}
return str;
}
}
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.
public class StringArraytest
{
public static List<string> generateStringArray(integer n)
{
integer i=5;
List<string> str= new List<string>();
for(i=0;i<n;i++)
{
str.add('test '+i);
system.debug(str[i]);
}
return str;
}
}
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.
Try the below code:
public class StringArrayTest {
public static List<String> generateStringArray(Integer length) {
List<String> myArray = new List<String>();
for(Integer i=0;i<length;i++) {
myArray.add('Test ' + i);
System.debug(myArray[i]);
}
return myArray;
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
All Answers
Try the below code:
public class StringArrayTest {
public static List<String> generateStringArray(Integer length) {
List<String> myArray = new List<String>();
for(Integer i=0;i<length;i++) {
myArray.add('Test ' + i);
System.debug(myArray[i]);
}
return myArray;
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj