Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ - Page 428 - Q6 - option D

 
Sean Hetfield
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HFSJ - P428 - Q6

<% java.util.List list = new java.util.ArrayList();

list.add("a");
list.add("2");
list.add("c");
requset.setAttribute("list", list);
requset.setAttribute("listIdx", "1");
%>
<%-- insert code here --%>

option D. ${list[listIdx+1]} is considered correct.

Can anyone let me know why this option is correct?

Thanks

Sean
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I see this option correct.
1- In the scriptlet you created one ArrayList object, added objects
to it.
2- You added this ArrayList object as request scoped attribute.
3- Another request scoped attribute is listIdx, whose value is 1.

[listIdx+1]-> first listIdx will be searched following the search order,
then arithmetic add operation will be done, result list[2] and you get
"c" as a result.


Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic