• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL problem

 
ani jadhao
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Just came across one question in a mock of EL.

11. <% java.util.Map map = new java.util.HashMap();
12. request.setAttribute("map", map);
13. map.put("a", "true");
14. map.put("b", "false");
15. map.put("c", "42"); %>
Which three EL expressions are valid and evaluate to true? (Choose three.)
A. ${not map.c} :

it return true in the answer.
I have tried in eclipse , it giving true .
But how , how can ${not 42} be evaluated to true.
Please help me to get out a this confusion.
--Ani
 
Rob Spoor
Sheriff
Pie
Posts: 20744
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "not" forces the remainder to be converted into a boolean. It uses Boolean.valueOf for that (section 1.14.2.1 of the specification), and Boolean.valueOf only returns true if the passed string is "true", "TRUE" or anything in between. In other words, after calling toLowerCase() the string must be "true".

All other strings will yield false, and map.c will result in "42" - or false. And therefore, the total will be !false which is true.
 
ani jadhao
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks dude . It clears !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic