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); }
2.1m questions
2.1m answers
60 comments
57.0k users