Is there a method in Java to check if a string can be used as a class name?
SourceVersion.isName can be used to check fully qualified names.
SourceVersion.isName
If no .s should be allowed, the check can be done this way:
.
boolean isValidName (String className) { return SourceVersion.isIdentifier(className) && !SourceVersion.isKeyword(className); }
1.4m articles
1.4m replys
5 comments
56.9k users