Supraja Jayakumar wrote:A small correction to the question: I want to set an upperlimit on the size of the hashmap.
Then strictly speaking I suspect you don't want to set an upper limit on the size of the HashMap; you want to set an upper limit on the number of buckets. And don't forget that HashMap actually applies a second hash to yours when it determines the bucket to put it in.
I have a feeling you might be better off using a TreeMap<Integer, Object> (or maybe a ConcurrentSkipListMap; it may be smaller) and simply adding objects and their hashcodes, and logging the times when your put() returns a non-null value. However, if your hash function is good, you may need an enormous number of objects before you get a collision. Alternatively, have a look at the HashMap source and duplicate its secondary hash for a particular size of "bucket map".
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here