Is String a Number - Java java.lang

Java examples for java.lang:String Parse

Description

Is String a Number

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String stra = "java2s.com";
        System.out.println(IsNumber(stra));
    }//from   www  .  j a v  a 2  s.  c  o m

    /**
     * 
     * @param stra
     *            input
     * @return is number
     */
    public static boolean IsNumber(final String stra) {
        try {
            if (stra == null || "".equalsIgnoreCase(stra)) {
                return false;
            }
            Long.parseLong(stra);
        } catch (Exception ex) {
            return false;
        }
        return true;
    }
}

Related Tutorials