Ramakant Biswal wrote:As we know the default size of HashSet is 16.
Ramakant Biswal wrote:My doubt is when we initializing the hashset HashSet empSet = new HashSet();, is it reserve array of 16 objects ??
If it does then what is the default value it store inside those objects.
Again we know each object are LinkedList, so what goes inside those LinkedList.
If it don't then what is the meaning of default size 16 for HashSet ??
Ramakant Biswal wrote:Thanks guys. Actually this question has asked to me in one of the interview.
I'm afraid there are some awfully stupid questions asked at interviews, but that's not your fault
Parvathi Raju wrote:while capacity is the maximum number of elements it can store at a given instance of time.
In the case of HashSet, that's actually not true.
1. "capacity" == "bucket bapacity"; and since a bucket can store any number of values, any HashSet can theoretically store as many values as it likes.
2. The actual limit of the number of values that can be stored is affected by the "load factor" which is normally set to 0.75, so with a "capacity" of 16, a re-hash will take place when you try to add the 13th value.
It's possible to discuss data structures such as hash sets, and that's a perfectly reasonable thing to ask a prospective programmer. Programmers should know about such things. But asking about internal details of Java's implementation of a hash set throws the question over the fence into "stupid" territory.
what is difference between hashset and hashmap?
What happens when you add duplicate to hashmap?
what would happen if you add key to hashmap which does not implement hashcode method?
Just want to know from this example what on hashmap would fall into ok question to ask.?
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
the value of filler advertising in 2021https://coderanch.com/t/730886/filler-advertising