You need to sign in to do that
Don't have an account?
dlCamelot
Converting Integer to String
Hi All,
I'm trying to get an array of strings returned based on Integer n, but seem to keep getting a value instead of a string. What do I need to adjust? Thanks!
public class StringArrayTest {
public void generateStringArray(){
List<String>stringArray = new List<String>{};
Integer n = 4;
for(Integer i=n;i<stringArray.size();i++){
String myInt = n.format();
stringArray.add('Test' + myInt);
}
return stringArray;
}
}
I'm trying to get an array of strings returned based on Integer n, but seem to keep getting a value instead of a string. What do I need to adjust? Thanks!
public class StringArrayTest {
public void generateStringArray(){
List<String>stringArray = new List<String>{};
Integer n = 4;
for(Integer i=n;i<stringArray.size();i++){
String myInt = n.format();
stringArray.add('Test' + myInt);
}
return stringArray;
}
}
Specifically ask yourself:
public class StringArrayTest{
public static List<string> generateStringArray(integer q){
list<string> test = new list<string>();
for(integer i=0; i < q;i++){
test.add('Test '+i);
}
return(test);
}
}
Mark as best answer if it works for you.
Please mark which ever of the above posts you feel most accurately leads you to the solution.
public class StringArrayTest {
public void generateStringArray(){ // void methods return void
List<String>stringArray = new List<String>{};
Integer n = 4;
for(Integer i=n;i<stringArray.size();i++){
String myInt = n.format();
stringArray.add('Test' + myInt);
}
return stringArray; // now your asking your void method to return something
}
}