---
title: "[转载]java中如何判断String中的内容是否为数字?"
author: "hotpro"
date: "2010-08-25T17:23:50Z"
tags: ["Blog", "Java"]
categories: ["编程语言"]
slug: "java-string"
draft: false
lastmod: "2010-08-25T17:29:31Z"
id: 747081
url: "https://hotpro.iteye.com/blog/747081"
---

可以用异常来做校验 
 
```java
   /**
     * 判断字符串是否是整数
     */
    public static boolean isInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * 判断字符串是否是浮点数
     */
    public static boolean isDouble(String value) {
        try {
            Double.parseDouble(value);
            if (value.contains("."))
                return true;
            return false;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * 判断字符串是否是数字
     */
    public static boolean isNumber(String value) {
        return isInteger(value) || isDouble(value);
    }  
```



原文链接： http://ap0406708.iteye.com/blog/446717