i am getting ClassCastException even if i am explicitely casting custom object into
string ..i want to know the reason why it is happening.
//any implementation of map will throw null pointer exception
import java.util.*;
class student
{
private String id;
public student(){}
public student(String id) {this.id=id;}
}
public class HashTableExample
{
public static void main(String args[])
{
Hashtable h = new Hashtable();
h.put("A","Apple");
h.put(new StringBuffer("p").toString(),"nitesh");
h.put(new student("p").toString(),"naresh");
Set<String> s=h.entrySet();
for(String str:s)
{
String s1=(String)h.get(s);
System.out.println(s1);
}
}
}
give me some suggestions
Thanks