How to validate if a string would be a valid java variable?

前端 未结 2 1653
别跟我提以往
别跟我提以往 2021-01-11 10:14

How can I best check if a string input would be a valid java variable for coding? I\'m sure I\'m not the first one who is willing to do this. But maybe I\'m missing the righ

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-11 10:55

    Just use the built-in isName method:

    public static boolean isName(CharSequence name)
    

    This returns whether or not a name is a syntactically valid qualified name in the latest source version.

    See the isName() documentation.

提交回复
热议问题