Ramakant Biswal wrote:As we know the default size of HashSet is 16.
To earn money on java go to upwork.com
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 ??
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ramakant Biswal wrote:Thanks guys. Actually this question has asked to me in one of the interview.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
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.
To earn money on java go to upwork.com
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.?
To earn money on java go to upwork.com
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |