Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a difference between Hashtable, HashMap and TreeMap? How do you decide which one to use?

Thank you
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable, HashMap and TreeMap are map implementations these collection classes should be used when you need to store data in key/value pairs.

Unlike the other two classes TreeMap is a Sorted map , sorts the element in the natural order. Hash Map & Hashtable are Unsorted & Unordered , Difference between Hashmap & hashtable is Hash map allows one null key & many null values but hash table does not . Also Hash table is synchronized
 
Stian Almaas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading the Collections trail at sun. That should answer your question.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also recommend the Collections chapter in Bruce Eckel's Thinking in Java. Reading it and doing the provided exercises will help a lot.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable is passe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic