Judging Java identifiers

Source: Internet
Author: User

1  PackageCom.jdk7.chapter5;2 3  Public classJavaidentifier {4     5     /**6 * Use Character.isjavaidentifierpart to determine if a character belongs to a Java identifier7 It's a letter8 It is a currency symbol (such as ' $ ')9 It is a connecting punctuation character (such as ' _ ')Ten It is a digit One It's a numeric letter (such as a Roman numeral character) A It is a combining mark - It is a non-spacing mark - ' \u005cu0000 ' through ' \u005cu0008 ' the ' \u005cu000e ' through ' \u005cu001b ' - ' \u005cu007f ' through ' \u005cu009f ' -      * @paramStr -      * @return +      */ -      Public Static Booleanisjavaidentifier (String str) { +         if(str==NULL|| Str.length () ==0){ A             return false; at         } -         Char[] ch =Str.tochararray (); -          for(inti=0;i<ch.length;i++){ -             if(!(Character.isjavaidentifierpart (Ch[i]))) { -                 return false; -             } in         } -         return true; to     } +      -      Public Static voidMain (string[] args) { theSystem.out.println ("My_var is an identifier?") +javaidentifier.isjavaidentifier ("My_var")); *System.out.println ("$my _var is an identifier?" +javaidentifier.isjavaidentifier ("$my _var")); $System.out.println ("My_var.1 is an identifier?") +javaidentifier.isjavaidentifier ("My_var.1"));Panax NotoginsengSystem.out.println ("1$my_var is an identifier?") +javaidentifier.isjavaidentifier ("1$my_var")); -System.out.println ("U0391var is an identifier?") +javaidentifier.isjavaidentifier ("U0391var")); theSYSTEM.OUT.PRINTLN ("Null is an identifier?") +javaidentifier.isjavaidentifier (NULL)); +SYSTEM.OUT.PRINTLN ("Null is an identifier?") +javaidentifier.isjavaidentifier ("")); A     } the } +  -  $ Execution Result: $My_var is an identifier?true -$my _var is an identifier?true -My_var.1 is an identifier?false the1$my_var is an identifier?true -U0391var is an identifier?trueWuyi NULLis an identifier?false the NULLis an identifier?false

Judging Java identifiers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.