• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

populating HTML tables in JSP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40793
828
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic