• 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 better performance HashMap or a TreeSet

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is more effeciant A HashMap or a TreeSet in terms of performace.

A HasMap is easier for me to implement by calling the key to get the value,
but would performace be a factor.

A treeSet will return the data in the order I added it from the record set.
But is more difficult to manipulate.

My problem is the output to a file has to be exact like so..

ID|Name|Address|zipcode etc..

Any suggestions?

RB
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I honestly don't think it is fair to compare HashMap with TreeSet because they serve two different purposes. A Map stores a value based on a key, whereas a Set stores unique values without a key. It might be more productive to compare HashMap with TreeMap or HashSet with TreeSet instead. Again, there is more to compare than just efficiency. TreeMap and TreeSet keep the elements in a sorted order (defined by the Comparable or Comparator interfaces), whereas HashMap and HashSet are unsorted. Of course, the sorting comes with an efficiency cost, so you have to take that into account. For more details, you should check out the Java API docs. They explain the efficiency considerations for these classes quite clearly (at least if you understand Big-Oh notation).

Layne
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might give you some implementation tips...

http://java.sun.com/docs/books/tutorial/collections/implementations/general.html

For more detailed information, see the "Choosing an Implementation" section in the "Collections" chapter of Bruce Eckel's Thinking in Java (about 3/4 of the way through the chapter)...

http://www.faqs.org/docs/think_java/TIJ313.htm
[ November 04, 2004: Message edited by: marc weber ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic