• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

populating HTML tables in JSP

 
munish plaza
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am required to get data from a server and populate it into a HTML table.The data can go upto 1000 rows.
If I have a code some thing like this(this is just a pseudo code)
<table border="1">
<% for(int j=0; j<hashtable.length; j++){ %>
<TR id>
<TD > <%=hashtable[j]%> </TD>

</TR>
<% } %>
</table>
How effective from performance point of view is the usage of for loop.
My data is contained in a hash table.What is the best approach that i can use.
Please help
Thanks
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I know why are you using hashtable and not hashmap? Hashmap methods are not synchronized and hence perform better.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your data stored in a HashTable (java class) or array named hashTable. From your code, it looks like you have an array.
If you are using an array, the for loop is effective. If you are using a HashTable, the syntax is wrong.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Is your data stored in a HashTable (java class) or array named hashTable. From your code, it looks like you have an array.
If you are using an array, the for loop is effective. If you are using a HashTable, the syntax is wrong.

Oops..It is an array and hot Hashtable
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For loop is effective if you have relatively large amounts of data.
If the number of records is known at compile time and you don't mind hardcoding that and writing a lot of duplicate code it's from a performance point better to unroll the loop.
But a loop is of course more flexible...
It's faster to (if possible) determine the actual length before entering the loop and setting that as the terminator rather than a function.
Saves a few clockticks on each iteration but is errorprone if the size of the array iterated over can change during the iteration (which can get ugly, but can be necessary).
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's faster to (if possible) determine the actual length before entering the loop and setting that as the terminator rather than a function.

Since array length is obtained from a field rather than a method it does not make any difference, i guess.
If ordering is not important reverse looping an array will be better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic