You need to sign in to do that
Don't have an account?
kotipalli srikanth
String array challenge from trailhead.
public class StringArrayTest {
public Static List<String> generateStringArray(integer n){
/* i want to know that, here the integer n is not initialized with any value, so how i<n works*/
List<String> myArray = new List<String> ();
for(integer i=0; i<n; i++){
myArray.add('Test' +i);
System.debug(myArray[i]);
}
return myArray;
}
}
// And also my above program is failing .
//help me please.
public Static List<String> generateStringArray(integer n){
/* i want to know that, here the integer n is not initialized with any value, so how i<n works*/
List<String> myArray = new List<String> ();
for(integer i=0; i<n; i++){
myArray.add('Test' +i);
System.debug(myArray[i]);
}
return myArray;
}
}
// And also my above program is failing .
//help me please.
All Answers
public class StringArrayTest {
public static String[] generateStringArray (Integer iCount) {
String[] myArray = new String[] {};
system.debug('Input parameter iCount: ' + iCount);
for (integer i=0; i<iCount; i++) {
myArray.add('Test ' + i);
system.debug('Array [' + i + ']: ' + myArray.get(i));
}
return myArray;
}
}
and you can use below code in Execute Anonymous window to test the code.
String[] finalArray = new String[] {};
finalArray = StringArrayTest.generateStringArray(2);
for (integer i=0; i<finalArray.size();i++){
System.debug('finalArray[' + i + ']: ' + finalArray.get(i));
}