• Post Reply Bookmark Topic Watch Topic
  • New Topic

a problem of Hashtable  RSS feed

 
David George
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String[] string = {"m","n"};
Hashtable<Integer,String[]> t = new Hashtable<Integer,String[]>();

public void test()
{
t.put(1,string);
}

public void get()
{
int[] string = -----
}

May i know how to turn the keys in HashTable to int[]???Thank you .
 
Thomas Paul Bigbee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what this is doing here, or why you would possible want to do what your trying to do, but anyway...

To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method.

The below code works, (and, I'll never confess to writing it)

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!