When you say colors.get(1);
or ${element[1]}
its actually referrign to single entry in the list. But when you use c:forEach
its iterating the loop.
It depends on what you are trying to achieve. If you just want the Nth element try
// This prints the second element of the list
but rather you want to print the entire elements you should go for loop like
Also please note if you write like
it literally treat the value as "colors"
. So if its a variable name you need to give it in ${}
like ${colors}
as depicted in example above.