一:

//1.用JAVA自带的函数
public static boolean isNumeric(String str){
for (int i = 0; i < str.length(); i++){
System.out.println(str.charAt(i));
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
//2.用正则表达式
首先要import java.util.regex.Pattern 和 java.util.regex.Matcher
public boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){
return false;
}
return true;
}

java中判断字符串是否为数字的方法的更多相关文章

  1. (转载)java中判断字符串是否为数字的方法的几种方法

    java中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < ...

  2. 字符串--java中判断字符串是否为数字的方法的几种方法?

    ava中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < ...

  3. java中判断字符串是否为数字的方法的几种方法

    1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ ...

  4. Java中判断字符串是否为数字

    转载:https://blog.csdn.net/u013066244/article/details/53197756 用JAVA自带的函数 public static boolean isNume ...

  5. Java中判断字符串是否为数字的五种方法

    //方法一:用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ ...

  6. Java中判断字符串是否为数字的五种方法 (转)

    推荐使用第二个方法,速度最快. 方法一:用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = str.length( ...

  7. 【工具类】Java中判断字符串是否为数字的五种方法

    1 //方法一:用JAVA自带的函数 2 public static boolean isNumeric(String str){ 3 for (int i = str.length();--i> ...

  8. java中判断字符串是否为数字的三种方法

    以下内容引自  http://www.blogjava.net/Javaphua/archive/2007/06/05/122131.html 1用JAVA自带的函数   public static ...

  9. [转]java中判断字符串是否为数字的三种方法

    1用JAVA自带的函数public static boolean isNumeric(String str){  for (int i = str.length();--i>=0;){      ...

随机推荐

  1. 【MongoDB】windows平台搭建Mongo数据库复制集(类似集群)(转)

    原文链接:[MongoDB]windows平台搭建Mongo数据库复制集(类似集群)(一) Replica  Sets(复制集)是在mongodDB1.6版本开始新增的功能,它可以实现故障自动切换和自 ...

  2. Sphinx(coreseek) 安装使用以及词库的扩展

    1.Sphinx(coreseek) 是啥 一般而言,Sphinx是一个独立的全文搜索引擎:而Coreseek是一个支持中文的全文搜索引擎,意图为其他应用提供高速.低空间占用.高结果相关度的中文全文搜 ...

  3. Routine Problem(数学)

     Routine Problem time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. C++的Trigraph

    ??=include <stdio.h> class HelloWolrd ??< public: void Trigraph() ??< printf("Hello ...

  5. STL中vector小结

    ()使用vector之前必须包含头文件<vector>:#include<vector> ()namespace std{ template <class T, clas ...

  6. codeforces Fedor and New Game

    #include<iostream> #include<stack> #include<cstring> #include<cstdio> #inclu ...

  7. Cwinux源码解析(一)

    我在我的个人博客发表了新的文章,欢迎各位读者批评指正. Cwinux源码解析(一)

  8. Linux的段错误调试方法

    linux段错误的调试方法 相关博文: http://blog.csdn.net/htianlong/article/details/7439030 http://www.cnblogs.com/pa ...

  9. Hadoop第6周练习—在Eclipse中安装Hadoop插件及测试(Linux操作系统)

    1    运行环境说明 1.1     硬软件环境 1.2     机器网络环境 2    :安装Eclipse并测试 2.1     内容 2.2     实现过程 2.2.1   2.2.2   ...

  10. [Node.js] BDD和Mocha框架

    原文地址:http://www.moye.me/2014/11/22/bdd_mocha/ 引子 今天造了个轮子:写了个深拷贝任意JavaScript对象的模块(事实上npm上已经有类似的模块,纯造轮 ...