
2 respuestas
It is odd that you are only getting one, however you would be getting at most two anyways. Since you are going from 0 - 1 since you minus'd the size of the array (3) and are using less than instead of less than or equals. If you want to debug this more, I would add a System.debug of i out before writing out your color.I would say that I would rewrite this method as follows:
or even betterpublic static void buildList() {
List<String> colors = new List<String>{
'red',
'green',
'blue'
};
for (Integer i = 0; i < colors.size(); i++) {
System.debug(colors.get(i));
}
}
public static void buildList() {
List<String> colors = new List<String>{
'red',
'green',
'blue'
};
for (String color : colors) {
System.debug(color);
}
}