• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EPractice Lab quiz 1 about delim in c:forTokens

 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How many iterations occur when the "delims" attribute of the c:forTokens is not specified?

a. 0
b. 1
c. Either A or B
Choice C is correct
The "delims" attribute specifies the set of delimiters (the characters that separate the tokens in the string). If it is null, items are treated as a single monolithic token. Depending on whether the "items" attribute is null or not, <c:forTokens> iterates exactly 1 time or does not iterate.
Thus, choice C is correct while choices A and B are incorrect.


As I tried, if I don't put delim attribute for c:forToken, the JSP does not compile.
If I put delim="", the string is iterated exactly once and print the whole string out.
So, the answer can be either B or does not compile.
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The delims attribute is the c:forToken is required. If omitted, it wouldn't compile.

Given the question as is, none of the answer choices are correct. A option D saying "won't compile" or "none of the above" will suit. Option B won't be correct.

However, have you tried
 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tsang,
I tried <c:forTokens var="token" items="...." delims=null >, but it does not compile. It wants me to put " " around the null.
Instead, I tried this. It delims by "n", "u" , "l"

The output is :

Str
ts, Spri
g, Hiber
ate, EJB
 
K. Tsang
Bartender
Posts: 3583
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting result.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic