I am dealing with problem. The code throws "java.lang.ClassNotFoundException: java.util.HashMap.Entry"
Class.forName("java.util.HashMap.Entry");
Anybody knows how can I create class to store HashMap.Entry?
Try:
Class.forName("java.util.HashMap$Entry");
(note the dollar sign.)
This works for me.
HashMap.Entry
isn't public, although it does exist. You should be able to fetch it (as java.util.HashMap$Entry
) but as it's not a public type you probably shouldn't be using it.
Map.Entry
is public, but it doesn't have that name - it's java.util.Map$Entry
due to being a nested class.
If you're hard-coding this, why not just use a class literal?
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Class<?> clazz = Map.Entry.class;
System.out.println(clazz.getName()); // java.util.Map$Entry
}
}