• 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

Collection

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.surfscranton.com/Architecture/JavaCollections.htm
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic