首页 > 编程知识 正文

java数值型转字符串,Java instanceof

时间:2023-05-03 15:11:40 阅读:29898 作者:2320

对象将移动到字符串、双精度、长整型、整型和布尔工具类

package com.myframework.utils;

importorg.Apache.com mons.lang3. string utils;

公共财务类铸造util {

//*

publicstaticstringcaststring{

returncaststring(obj,'');

}

//*

publicstaticstringcaststring (zldqc,字符串默认值) {

返回Obj!=null? string.valueof(obj ) :默认值;

}

//*

publicstaticdoublecastdouble{

returncastdouble(obj,0 );

}

//*

publicstaticdoublecastdouble (zldqc,双默认值) {

双值=默认值;

if(obj==null ) {

返回值;

}

stringstrvalue=caststring(obj;

if (string utils.is not empty (strvalue ) ) )

try {

value=double.parse double (strvalue );

}catch(numberformatexceptione ) )

value=默认值;

}

}

返回值;

}

//*

publicstaticlongcastlong(zldqc ) {

返回语句(obj,0 );

}

//*

publicstaticlongcastlong(zldqc,长默认值) {

long value=默认值;

if(obj==null ) {

返回值;

}

stringstrvalue=caststring(obj;

if (string utils.is not empty (strvalue ) ) )

try {

value=long.parselong(strvalue );

}catch(numberformatexceptione ) )

value=默认值;

}

}

返回值;

}

//*

publicstaticintcastint(zldqc ) {

返回语句(obj,0 );

}

//*

publicstaticintcastint(zldqc,int默认值) {

int value=默认值;

if(obj==null ) {

返回值;

}

stringstrvalue=caststring(obj;

if (string utils.is not empty (strvalue ) ) )

try {

value=integer.parseint (strvalue );

}catch(numberformatexceptione ) )

value=默认值;

}

}

返回值;

}

//*

publicstaticbooleancastboolean {

返回语句(obj,false );

}

//*

publicstaticbooleancastboolean (zldqc,布尔默认值) {

boolean value=默认值;

if(obj!=空) {

value=boolean.parse boolean (caststring (obj );

}

返回值;

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。