File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection

 
jose chiramal
Ranch Hand
Posts: 266
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats difference between

1. HashSet and LinkedHashSet. When do we used HashSet and when do we use LinkedHashSet ?
2. SortedSet and Tree Set. When do we use SortedSet and TreeSet ?
 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. LinkedHashSet keeps the order of element.
2. SortedSet is an interface and TreeSet is a concrete class implementing the SortedSet.

And the JavaDocs itself explains it beautifully.
 
Tukaram Ugile
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashSet is used when we want to get the unique elements by random order.
When we want these elements to be retrieved in the insertion order we can go for LinkedHashSet.

We use the TreeSet when we want the unique elements to be sorted in specific order.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose also focus on NavigableSet which is a far more versatile interface than SortedSet. The subSet(from,in,,to,in) syntax and other variants like tailSet, headSet which provide inclusive boolean in their argument produce NavigableSet. The older type syntax of subSet(from,to) produce SortedSet. This is true of their Map equivalent too.


 
Brij Garg
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose,

Just a suggestion

I think it will be great , if you share your understanding about collections and then we can have a healthy discussion about collection. It will help everyone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic