Maximum capacity of a Hashtable
1 posts in topic
Flat View  Flat View

Posted By:   Luke_Latimer
Posted On:   Friday, August 31, 2001 01:46 AM

I'm reading a csv file into a Hashtable

The file has 60,000 rows, but when I query the Hashtable.size() it returns approx 2000.

I've tried setting the capacity using the constructor, new Hashtable(60000) but this doesn't seem to make any difference.

Can anyone suggest something I've done wrong or perhaps a different approach?

Re: Maximum capacity of a Hashtable

Posted By:   Kevin_Riff  
Posted On:   Friday, September 21, 2001 03:00 PM

The capacity of a hashtable only allocates room for a certain number of entries. The hashtable usually will have fewer entries than its capacity. Exactly how many entries it will hold for a given capacity depends on its load factor.

Are you sure that each row of that 60,000 line file has a unique key? I suspect that you have many, many duplicates and only about 2000 unique keys. In this situation you will find that you're overwriting older entries rather than creating new ones.

Try checking the containsKey() method prior to adding an entry. If it returns true then you have a duplicate.

About | Sitemap | Contact