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

What is the fastest way to loop in java in huge data structure

 
Ranch Hand
Posts: 620
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He all
i have data structure that is list that in every element there is hashtable that contains key value pairs, there is no limit on the list size
and it can be 500 elements long , now the thing is i need to out put this structure content as string , to do simple loop on the list and drill
to each hashtable and get the key value as string will take very long time .
how can i optimize this task? and make this action with minimum cpu ?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your requirement is to output the whole data structure (is it?), then surely you cannot avoid traversing the whole list and every hash map. You can use an Iterator or an enhanced "for" loop to do so.

If you're building up a huge String from the data, do use StringBuilder. This is better than StringBuffer because it avoids unnecessary synchronisation. Both are much better than String concatenation using "+" as that creates a lot of unnecessary temporary objects.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Meir Yan:

i have data structure that is list that in every element there is hashtable that contains key value pairs, there is no limit on the list size
and it can be 500 elements long , now the thing is i need to out put this structure content as string , to do simple loop on the list and drill
to each hashtable and get the key value as string will take very long time .
how can i optimize this task? and make this action with minimum cpu ?



What do you mean by "very long"? How much time did it take when you tried?

500 elements aren't particularly many - it shouldn't take longer than a few milliseconds to iterate through them, even when using a non-optimized approach.

Moving to our Performance forum...
reply
    Bookmark Topic Watch Topic
  • New Topic