• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HFSJ - Page 428 - Q6 - option D

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic