Whether there are numbers in the Java string

Source: Internet
Author: User




1  packagecn.sunzn.demo;2 3 Importjava.util.regex.Matcher;4 Importjava.util.regex.Pattern;5 6  public classDemo {7      public Static voidmain (string[] Args) {8System.out.println (iscontainchinese ("china")));9     }Ten  one      public Static BooleanIscontainchinese (String Str) { a  -Pattern p = pattern.compile ("[\u4e00-\u9fa5]"); -Matcher m =P.matcher (str); the         if(m.find ()) { -             return true; -         } -         return false; +     } -}

In my own case, find works.

1  packagesdf;2 3 Importjava.util.regex.Matcher;4 Importjava.util.regex.Pattern;5 6  public classD {7 8      public Static Booleanisnumeric (String Str) {9          for(inti = Str.length (); I. >= 0;) {Ten             if(!character.isdigit (str.charat (i))) { one                 return false; a             } -         } -         return true; the     } -      public Static voidmain (string[] Args) { -         //TODO auto-generated Method Stub -  +String s1= "25"; -String s2= "retake"; +Pattern pattern = Pattern.compile ("\\d+"); a          atMatcher Matcher1 =Pattern.matcher (s1); -           //boolean b1= matcher1.matches (); -           Booleanb1=Matcher1.find (); - System.out.println (b1); -            -Matcher Matcher2 =Pattern.matcher (s2); in           //boolean b2= matcher2.matches (); -           BooleanB2=Matcher2.find (); to System.out.println (b2); +          -         //System.out.println (isnumeric (s1)); the        //System.out.println (isnumeric (s2)); *  $     }Panax Notoginseng  -}

Whether there are numbers in the Java string

Related Article

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.