![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
java 判断字符串是不是数字
1个回答
展开全部
用instanceof关键字判断,参考下面代码
Object param = params.get(i);
if (param instanceof Integer) {
int value = ((Integer) param).intValue();
prepStatement.setInt(i + 1, value);
} else if (param instanceof String) {
String s = (String) param;
prepStatement.setString(i + 1, s);
} else if (param instanceof Double) {
double d = ((Double) param).doubleValue();
prepStatement.setDouble(i + 1, d);
} else if (param instanceof Float) {
float f = ((Float) param).floatValue();
prepStatement.setFloat(i + 1, f);
} else if (param instanceof Long) {
long l = ((Long) param).longValue();
prepStatement.setLong(i + 1, l);
} else if (param instanceof Boolean) {
boolean b = ((Boolean) param).booleanValue();
prepStatement.setBoolean(i + 1, b);
} else if (param instanceof Date) {
Date d = (Date) param;
prepStatement.setDate(i + 1, (Date) param);
}
Object param = params.get(i);
if (param instanceof Integer) {
int value = ((Integer) param).intValue();
prepStatement.setInt(i + 1, value);
} else if (param instanceof String) {
String s = (String) param;
prepStatement.setString(i + 1, s);
} else if (param instanceof Double) {
double d = ((Double) param).doubleValue();
prepStatement.setDouble(i + 1, d);
} else if (param instanceof Float) {
float f = ((Float) param).floatValue();
prepStatement.setFloat(i + 1, f);
} else if (param instanceof Long) {
long l = ((Long) param).longValue();
prepStatement.setLong(i + 1, l);
} else if (param instanceof Boolean) {
boolean b = ((Boolean) param).booleanValue();
prepStatement.setBoolean(i + 1, b);
} else if (param instanceof Date) {
Date d = (Date) param;
prepStatement.setDate(i + 1, (Date) param);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询