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.

[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>

.
[/java]




Author: Ravi Bandakkanavar

A Techie, Blogger, Web Designer, Programmer by passion who aspires to learn new Technologies every day. It has been 6 years since I have been publishing articles and enjoying every bit of it. I want to share knowledge and build a great community with people like you.

Suggested articles for you:

Did it help? Comment here..