工具类(自己的)


package utils;

/**
 * 工具类
 * @author tsp
 *
 */
public class OUtils {
	

	public static int ZERO = 0;				//零
	
	/**	字符串是否为null或者为""
	 */
	public static boolean isEmpty(String text){
		return text == null || text.length() == 0;
	}
	
	/**	字符串是否为null或者""
	 */
	public static boolean isEmpty(Object obj){
		return obj == null || String.valueOf(obj).length() == 0;
	}
	
	/**	如果字符串为null 返回""
	 */
	public static String getN(String text){
		return text == null ? "":text;
	}
	
	/**	获取随机数	取4位
	 */
	public static String getRandomAndFour(){
		return	String.valueOf((int)(Math.random()*9999)+1000);
	}
	
	/** 转换,失败返回0
	 */
	public static int parseInt(String val){
		int result = 0;
		try{
			result = Integer.parseInt(val);
		}catch(Exception e){
			
		}
		return result;
	}
	
	/** 转换,失败返回0
	 */
	public static long parseLong(String val){
		long result = 0;
		try{
			result = Long.parseLong(val);
		}catch(Exception e){
			
		}
		return result;
	}
	
	/** 转换,失败返回0
	 */
	public static float parseFloat(String val){
		float result = 0;
		try{
			result = Float.parseFloat(val);
		}catch(Exception e){
			
		}
		return result;
	}
	
	/** 转换,失败返回0
	 */
	public static float parseFloat(String val,float def){
		try{
			return Float.parseFloat(val);
		}catch(Exception e){
			
		}
		return def;
	}
	
	/** 转换,失败返回0
	 */
	public static double parseDouble(String val){
		return parseDouble(val,0);
	}
	
	/** 转换,失败返回0
	 */
	public static double parseDouble(String val,double def){
		try{
			return Double.parseDouble(val);
		}catch(Exception e){
			
		}
		return def;
	}
	
	/** 转换,失败返回0
	 */
	public static String parseFloatStr(String val){
		String result = "0";
		try{
			Float.parseFloat(val);
			result = val;
		}catch(Exception e){
			
		}
		return result;
	}
	
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值