JSP page to display ArrayList elements using Iterator

By | May 30, 2015

An Example which explains how to display ArrayList elements using Iterator interface in java.


//ArrayList which contains list of subject names which is coming

<%
ArrayList<Test> subjectList =(ArrayList) request.getAttribute("subjectList");
%>
<form action="StudentController" name="formName" method="post" >
<table cellspacing="2" cellpadding="2">
<tr><th>Subject List</th><th>Select Test</th></tr>

<%
// Iterating through subjectList
Iterator<Test> iterator = subjectList.iterator();
while(iterator.hasNext())
{
Test testBean = iterator.next();
%>
<tr><td><%=testBean.getSubjectId()%></td> 
<td>
<input type="radio" name="subject" value="<%=testBean.getSubjectId()%>"/>
</td></tr>
<%
}
%>
</table>
<input type="submit" value="Take Test" />
</form>

.
Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *