Thursday, April 30, 2015

HashSet internal implementation in Java

HashMap.put method will return
 
  oldValue: if key is already present, then it will overwrite the value and returns old value
  null: if key is not present, then it will add this key,value pair and then returns null.

In case of HashSet, internally it has a hashmap. When we call add method it will call 'put' method of the hashmap and if put method returns null means new entry is added into hashmap and hashset

more at: http://javahungry.blogspot.com/2013/08/how-sets-are-implemented-internally-in.html

No comments:

Post a Comment