• Post Reply Bookmark Topic Watch Topic
  • New Topic

For sorted traversal of Set  RSS feed

 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that For sorted traversal, it is generally faster to add elements to a HashSet, then convert the collection to a TreeSet
Is it right? If yes, then could you please tell me the reason?
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you read that? Faster than what? Than adding all your values to s SortedSet in the first place? That seems peculiar; adding to a HashSet is constant time, and adding to a TreeSet is logarithmic time, so adding all the elements from one set to another runs in nlog(n) time.

Please provide more details of what you read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!