1

I have one arraylist

  ArrayList al = new ArrayList();
  al.add("tree good has");
  al.add("ok go by");
  al.add("see good");
  al.add("dog");

how to add " span " to each words??? For example:

  <li> 
     <span>tree</span>  
     <span>good</span> 
     <span>has</span> 
  </li>
  <li> 
     <span>ok</span>  
     <span>go</span> 
     <span>by</span> 
  </li>
  <li> 
     <span>see</span>  
     <span>good</span> 
  </li>
  <li> 
     <span>dog</span> 
  </li>

what i tried was: the result of this statement was wrong. because the result is add " span " to each row , not earch word.

 <% for (int i=0; i<  al.size();i++){ %>
    <li><span><%=al.get(i) %><br></span></li>  
 <%} %> 

how to add " span " to each words???

Chirag Parmar
  • 833
  • 11
  • 26
bob90937
  • 553
  • 1
  • 5
  • 18
  • It depends on how much span do you want to put for each
  • . I guess in this case you want to put every span in the same line. put your
  • out of for and if you want to make more
  • , use double for.
  • – uelordi Nov 03 '16 at 08:06
  • DId you know EL ? http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files?rq=1 This would be cleaner and the logic of the solutions are the sames – AxelH Nov 03 '16 at 09:12