Re: HashMap Capacity Argument.
- From: "Fred" <ffaber@xxxxxxxxx>
- Date: 13 May 2005 05:40:18 -0700
You can back this out from the load factor. The load factor, for the
purposes of this post, represents the maximum percentage of the
capacity of the HashMap that may be populated. The HashMap will be
resized when its size exceeds a threshold value, computed by:
threshold = (int)(capacity * loadFactor);
The default load factor is .75f. Given this, lets say you know you're
storing at most 100 keys. You can then construct your HashMap by the
following:
(1) hm = new HashMap( 134 ); // because (100 / 134) < .75
or in general
(2) hm = new HashMap( c, f ); // where ( 100 / c ) < f
Check the source code for HashMap for futher insight, but I think this
is info enough to answer your post.
-Fred
.
- References:
- HashMap Capacity Argument.
- From: MrFredBloggs
- HashMap Capacity Argument.
- Prev by Date: Re: Apache and Tomcat
- Next by Date: Null Pointer exception when using web services
- Previous by thread: HashMap Capacity Argument.
- Next by thread: xml trouble
- Index(es):
Relevant Pages
|