Java custom method for determining whether a string is a number

Source: Internet
Author: User

Tag:logs   span    string    asc   mpi     Custom    http   char   color   

 //  method one: function with Java  public  static  boolean " Span style= "COLOR: #000000" > IsNumeric (String str) { for  (int  i = str.length ();--i>=0;) { if  (! Character.isdigit (Str.charat (i)) { return  false  ; }}  return  true   
 /*   method Two: recommended, fastest (disputed) * Determine if integer * @param str The string passed in * @return is an integer that returns true, otherwise false  */  Public  static  boolean   Isinteger (String str) {pattern pattern  = Pattern.compile (" ^[-\\+]?[          \\d]*$ ");     return   Pattern.matcher (str). matches (); }
 //  method Three:   Public  static  boolean   IsNumeric (String str) {pattern pattern  = Pattern.compile (" [0-9]* "     return   Pattern.matcher (str). matches (); }
 //  method four:   Public  final  static  boolean   IsNumeric (String s) { if  (s! = null  &&! "" " .equals (S.trim ()))     return  s.matches ("^[0-9]*$"  else  return  false  ;}  
      public static Boolean isnumeric (String str) {for (  int i=str.length ();--i>=0;) {        int chr=str.charat (i);         if (chr<48 | | chr>57)             return false ;    }    return true ;}

Turn from: https://www.cnblogs.com/heyuxiu/p/5972187.html [Thank you very much:)]

Java custom method for determining whether a string is a number

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.