I was working on a Java web application, and had the following requirement with respect to looping in my HTML table.
I’ve a nested for loop inside a while loop(both execute the same # of times, for ex. say 3).
My code looks something like this:
<table>
<thead>...</thead>
<tbody>
if (patcases != null && patcases.size() > 0) {
Iterator itr1 = patcases.iterator();
while (itr1.hasNext()) {
..some code here..
System.out.println("DA Email from webpage..."+da.getEmail());
int rCount = 0;
<tr>
for(int i=0;i<passedValues.length; i++){
...some code here..
</tr>
System.out.println("Printed row..." +rCount);
rCount ++;
} /*closing of for loop */
}/*closing of while loop */
}/* closing of if loop */
</tbody>
</table>
Now, with this type of looping structure, I get the following on my console:
DA Email from webpage…abc@abc.com
Printed row…0
Printed row…1
Printed row…2
DA Email from webpage…xyz@xyz.com
Printed row…0
Printed row…1
Printed row…2
DA Email from webpage…123@123.com
Printed row…0
Printed row…1
Printed row…2
But the type of output I wanted was, something as follows:
DA Email from webpage…abc@abc.com
Printed row…0
DA Email from webpage…xyz@xyz.com
Printed row…1
DA Email from webpage…123@123.com
Printed row…2
How would I go about doing this?
Any help would be greatly appreciated.
It looks like you want parallel iteration.
Simply do something like this:
Note that if at all possible, so you should use parameterized types instead of raw types (Effective Java 2nd Edition, Item 23: Don’t use raw types in new code).