Given a class name as a string, how do I get the package name of it at run time ? I do not have the fully qualified name with package name + class name. Simply only the clas
final Package[] packages = Package.getPackages();
final String className = "ArrayList";
for (final Package p : packages) {
final String pack = p.getName();
final String tentative = pack + "." + className;
try {
Class.forName(tentative);
} catch (final ClassNotFoundException e) {
continue;
}
System.out.println(pack);
break;
}