• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 8945
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: 42003
911
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: 8945
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: 8945
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.
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic