I have an Arraylist of Arraylist< String>'s and I am trying to access a string value. Say I wanted to access the third String in the second ArrayList in my jsp f开发者_JS百科ile, but I wanted to do it without scripting, using EL. would this be correct? ${anArrayList[2][3]}
Almost correct. Array indexes start with 0
, not 1
as you seem to think. This has always been the case in normal Java code and this is not different in EL. So, to get the second list and then the third string, you need respectively the indexes 1
and 2
. So, this should do
${anArrayList[1][2]}
...assuming that you've already placed ${anArrayList}
in the desired scope. For example, in the request scope with help of a preprocessing servlet:
List<List<String>> anArrayList = createItSomehow();
request.setAttribute("anArrayList", anArrayList);
// ...
// I'd invent a more self-documenting variable and attribute name though.
By the way, are you familiar with Javabeans? This smells much that you rather need a List<Entity>
.
精彩评论