File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hashtable" Watch "Hashtable" New topic


Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
Can anyone show me how to build a hashtable to test for some string values to see how they would hash into a table. It's late and I may not be to asking this just right.I want to make a test hashtable, insert some words and see where they are put in the table. would like the size of the table to be 101, but everytime I try to call what I've done I get an error saying I can't use [] to find the position. I can give you what I have for code but it's far from finished I fear.

If you can be of any help I thank you.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I guess you are more used to C++/STL than Java, as the program above has a lot of other conversion issues too. In Java, a variable is just a reference, so you always need to initialize them before use. T is declared as a reference to a Hashtable, for example, but nowhere does it say T = new Hashtable(), so T is always null. Likewise for M which is never initialized and so remains at 0 (it may look as if it is initialized in one of the constructors, but that actually just assigns a value to a local variable which is then discarded).

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
I want to thank you both, I am just getting started at this and I know there are a lot of problems with the code. Is there a way to write a hashtable without using Java's Hashtable class to solve the problem above?
I agree. Here's the link:
subject: Hashtable
It's not a secret anymore!