java中判断字符串是否为数字的三种方法
java中判断字符串是否为数字的三种方法
1>用JAVA自带的函数
public static boolean isNumeric(String str){
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
2>用正则表达式
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3>用ascii码
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;
}
4>用异常
public static boolean isNumeric(String str){
try{
Integer.parseInt(str);
}
catch(NumberFormatException ne){
return false;
}
return true;
}
相关文档:
JAVA之IO流(超详细的Java.io包的介绍!)
一.Input和Output
1.stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源。
在Java的IO中,所有的stream(包括Input和Out stream)都包括两种类型:
1.1 以字节为导向的stream
以字节为导向的stream,表示以字节为单位从stream中读取或往stream中写入信� ......
RT
package
com.fxt.test;
import
org.apache.commons.mail.EmailException;
import
org.apache.commons.mail.SimpleEmail;
public
class
Mail {
public
static
void
m ......
在Java中有两种不同的对变量赋值方式,一种是直接将一个值赋给变量。例如:
int a = 1;
String s = "abc";
Integer in = 125;
另外一种是创建一个对象,并将其赋给一个变量。例如:
String s = new String("abc")
Integer in = new Integer(125);
两种方式的不同之处在于:
第一种方式变量的值存储在堆栈中,当下一 ......
本文讲述程序开发者怎样使用NetBeans 6.8 IDE和JavaFX技术创建他们的第一个JavaFX应用程序。在文章中,我们将创建一个简单的带有文本的球体。该球体在一个特定的时间周期内改变其透明度。你还可以使用鼠标拖动球体。
同样的原因,因为文内有很多操作截图,这里插入很不方便, ......
本文来自:http://blog.csdn.net/ruyanhai/archive/2007/11/07/1871663.aspx
◆ 一般情况下,我们都使用相对路径来获取资源,这样的灵活性比较大.
比如当前类为com/bbebfe/Test.class
而图像资源比如sample.gif应该放置在com/bbebfe/sample.gif
而如果这些图像资源放置在icons目录下,则应该是com/bbebfe/icons/sample.gif ......