Java Number Parse isNumber(String str)

Here you can find the source of isNumber(String str)

Description

This method is used to check if the String passed is a number/integer only.

License

Apache License

Parameter

Parameter Description
str a parameter

Return

boolean

Declaration

public static boolean isNumber(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;
import java.text.ParsePosition;

public class Main {
    /**//w w  w .  j  a va 2s. c o  m
     * This method is used to check if the String passed is a number/integer only.
     * @param str
     * @return boolean
     */
    public static boolean isNumber(String str) {
        NumberFormat formatter = NumberFormat.getInstance();
        ParsePosition pos = new ParsePosition(0);
        formatter.parse(str, pos);
        return str.length() == pos.getIndex();
    }
}

Related

  1. isNumber(final String str)
  2. isNumeric(Class cls)
  3. isNumeric(final String str)
  4. isNumeric(String str)
  5. isNumeric(String str)