File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Duplication removal from Set

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How set collection manages to remove duplicate objects from it. If entry of every object checked by equals from all present object then it is a very lengthy process to do it. Is it by the same way or some other way around?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HashSet for example just uses an internal HashMap to manage its elements. That way it's possible to guarantee that certain operations only take constant time, i.e. it's equally fast, no matter how big the set may grow. The API documentation of HashSet says the following:
This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets.


Basically that's possible because HashMap uses the hashCode() method to handle its elements which makes it unnecessary (depending on the quality of the produced hashes) to compare new elements to each existing element.

Marco
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marco
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic