• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference between HashSet and HashTable?

 
Deepika Singh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could anyone tell me the difference between HashSet and HashTable, Comparator and Comparable, Array and Collections.


Thanks a lot.....
 
Arka Guhathakurta
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashSet is a Set and Hashtable is a Map. You have to read Set and Map interfaces to know the difference. You use Comparable's compareTo method to compare two objects of a class. That basically menas that implementing a comparable interface will make your class to be used to calculate HashCode. However comparator can be used to compare one or more objects. Array is a contiguous collection of similar data-types (generally) whereas collection is a type safe arrangement of objects. Collections framework will tell more. Please correct me if I am wrong.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepika Singh wrote:Could anyone tell me the difference between HashSet and HashTable, Comparator and Comparable, Array and Collections.

Have you looked at the JavaDocs for those classes?
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arka Guhathakurta wrote:HashSet is a Set and Hashtable is a Map. You have to read Set and Map interfaces to know the difference. You use Comparable's compareTo method to compare two objects of a class. That basically menas that implementing a comparable interface will make your class to be used to calculate HashCode. However comparator can be used to compare one or more objects. Array is a contiguous collection of similar data-types (generally) whereas collection is a type safe arrangement of objects. Collections framework will tell more. Please correct me if I am wrong.


A small adding for what Arka said A Set is a collection that has no duplicate elements. A map is a way of storing key/value pairs. The way of storing a Map is similar to two-column table and for detailed information see java documentation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic