java 校验数据是否为int、double、string类型的方法instanceof

String sContentValue = "1234567";
boolean bCheckResult = true;
/* Int */
try
{
	Integer iCheckValue = Integer.parseInt(sContentValue);
				
	if (iCheckValue instanceof Integer == false)
	{
		bCheckResult = false;
	}
}
catch(NumberFormatException e)
{  
	bCheckResult = false;
}
/* Double */
try
{ 
	Double dCheckValue = Double.parseDouble(sContentValue);
    	if (dCheckValue instanceof Double == false)
    	{
     		bCheckResult = false;
    	}
}
catch(NumberFormatException e)
{  
    	bCheckResult = false;
}
/* String */
if (sContentValue instanceof String == false)
{
	bCheckResult = false;
}

 
  
 
 

你可能感兴趣的:(Android)