The requirement is to use a user defined object as a key. But I want the hash table to consider two user defined objects with same values as single key.
What is the best solution to print �value of 10� and null as output for the two print statements? look at this code
import java.util.Hashtable;
/**
* Simple key Class
*
* @author
* @version
*/
class Key {
private int i;
private
String s;
Key(int i, String s) {
this.i = i;
this.s = s;
}
public int getI() {
return i;
}
public String getS() {
return s;
}
}
public class TestHash {
public static void main(String[] args) {
Hashtable ht = new Hashtable();
ht.put(new Key(10, "I am 10"), "Value of 10");
System.out.println("Get with Same key different object: " + ht.get(new Key(10, "I am 10")));
System.out.println("Get with another key: " + ht.get(new Key(11, "I am 10")));
}
}
Thanks
Chennarao