- Can Hashtable have any number of records in it?
- Is it efficient to use Hashtable in case we have more records (eg. Some 10000 records)?
And are there any disadvantages of using Hashtable in terms of Efficiency .?
Thanks.
And are there any disadvantages of using Hashtable in terms of Efficiency .?
Thanks.
The disadvantage of HashTable in terms of efficiency is:
Hash tables become quite inefficient when there are many collisions. While extremely uneven hash distributions are extremely unlikely to arise by chance, a malicious adversary with knowledge of the hash function may be able to supply information to a hash that creates worst-case behavior by causing excessive collisions, resulting in very poor performance, e.g. a denial of service attack.[21] In critical applications, universal hashing can be used; a data structure with better worst-case guarantees may be preferable.[22]
You can use HashMap as they are better and a good option instead of HashTable.
In general, HashMap will be a better option in terms of efficiency, as it's not synchronized.
Take a look at this:
http://blog.manishchhabra.com/2012/08/the-5-main-differences-betwen-hashmap-and-hashtable/
Hashtable is (as good as) deprecated. Use HashMap
or ConcurrentHashMap
based on whether you want your data to be threadsafe or not.
It depends on the implementation. One way to implement a hash table is to make the initial table not so big, and if the load factor (ratio of used elements vs available slots) increases beyond a threshold, increase the table size Check the wikipedia article for more understanding http://en.wikipedia.org/wiki/Hash_table#Perfect_hash_function
ok thanks for the advice ,I am new on stackoverflow. so answer to question 1 is Yes you can add any number of record as long as you don't overflow. and answer to 2 question is Hashtable is synchronized (Thus overhead) so if you don't need synchronization and thread safety then go for HashMap
When using a hash algorithm that causes a lot of collisions, it is not appropriate to use a hash table because it will change lookup and insert from O(1) to O(log n).