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.
it looks like you are doing trailhead, be sure to read the example from top to bottom before trying out the exercise.
That said, here's the general guideline.
The Apex class must be called 'StringArrayTest' and be in the public scope. --> public class StringArrayTest{ The Apex class must have a public static method called 'generateStringArray'. -->public static List<String> generateStringArray(Integer n) {
The 'generateStringArray' method must return an array (or list) of strings. -->public static List<String> generateStringArray(Integer n) {
Each string must have a value in the format 'Test n' where n is the index of the current string in the array. s= 'Test ' + x;
The number of returned strings is specified by the integer parameter to the 'generateStringArray' method. public static List<String> generateStringArray(Integer n) {
The whole solution:
public class StringArrayTest{
public static List<String> generateStringArray(Integer n) {
List<String> ListFields = new List<String>();
String s;
integer x;
for (x=0;x<n;x++){
s= 'Test ' + x;
ListFields.add(s);}
return(ListFields);
}
}
it looks like you are doing trailhead, be sure to read the example from top to bottom before trying out the exercise.
That said, here's the general guideline.
The Apex class must be called 'StringArrayTest' and be in the public scope.
--> public class StringArrayTest{
The Apex class must have a public static method called 'generateStringArray'.
-->public static List<String> generateStringArray(Integer n) {
The 'generateStringArray' method must return an array (or list) of strings.
-->public static List<String> generateStringArray(Integer n) {
Each string must have a value in the format 'Test n' where n is the index of the current string in the array.
s= 'Test ' + x;
The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
public static List<String> generateStringArray(Integer n) {
The whole solution:
public class StringArrayTest{
public static List<String> generateStringArray(Integer n) {
List<String> ListFields = new List<String>();
String s;
integer x;
for (x=0;x<n;x++){
s= 'Test ' + x;
ListFields.add(s);}
return(ListFields);
}
}
To run it use:
StringArrayTest.generateStringArray(10);
where 10 can be any number.
In the developer's console type this in:
System.debug(StringArrayTest.generateStringArray(10));
and this should be the result:
USER_DEBUG [1]|DEBUG|(Test 0, Test 1, Test 2, Test 3, Test 4, Test 5, Test 6, Test 7, Test 8, Test 9)
Thx
Your code should be like below. And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window
Paste below code in it Please let us know if this will help you
Thanks
Amit Chaudhary