Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hashtable

Status
Not open for further replies.

sherilu23

Technical User
Jun 24, 2000
7
CA
I created a class HashString that extends Hashtable and implements Map. HashString class is suppose to read all the words/strings from a file and store the unique value in Hashtable.
in my main method I have the following:

public static void main( String [ ] args )
{
HashString word = new HashString(initialCapacity);

System.out.println( "Checking... (no more output means success)" );

try {
BufferedReader in = new BufferedReader(new FileReadeR("venusandadonis"));

String l,w;
StringTokenizer str;

while ((l = in.readLine()) != null)
{
str = new StringTokenizer(l);
while (str.hasMoreTokens()) {
w = str.nextToken();

if (!(word.containsValue(w)) && word.isEmpty())
word.put(initHash(w), new String (w));
else
{ while(!(word.isEmpty()) && word.containsValue(w))
word.put(probeHash(w), new String(w));

}
}
}
}catch(Exception e) { System.err.println("error"); }
}

where initHash produces a hash function and probeHash probes the hashtable quadratically.
I get the following compilation error:
method put(int, java.lang.String) not found in class HashString

From what I understand, method put(key, value) is already defined in class Hashtable. And HashString is extending it so therefore HashString should inherit the put(x,y) method. Am I missing something??? I've tried using array initially for my hashtable, didn't work. Then I discovered yesterday about Hashtable class, so I'm hoping it'll work this time. Any help would be GREATLY appreciated.
Thanks in advance.
 
Dear sherilu23,

The actual signature of the put method in Hashtable is:

public synchronized Object put(Object key, Object value)

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top