简单封装JAVA空判断

    在项目开发过程中,面对各种各样的对象,如果稍不注意,就会发生NULL空指针报错;是不是很烦恼,特别是对重要的参数判读;

    经过总结,把各种类型的空判断进行了简单的封装,对新手还是很方便的;

package com.xt.shop.until;

import java.util.List;

/**
 * <p>判断 对象 是否为空
 * <p>返回值:为空  ? true : false
 * <p>创建人:geYang
 * <p>创建时间:2017.8.1
 */
public class IsNull {

	/**
	 * 判断字符串是否为空
	 * */
	public static boolean isNull(String str){
		if(str!=null){
			str = str.trim();
		}
		return str == null || str.isEmpty();
	}
	
	/**
	 * 判断List数组是否为空
	 * */
	public static boolean isNull(List<?> list){
		return list == null || list.isEmpty(); 
	}
	
	/**
     * 判断Integer数组是否为空
     * */
	public static boolean isNull(Integer[] arr){
	    return arr==null || arr.length<1;
	}
	
	/**
	 * 判断整数是否为空(ID)
	 * */
	public static boolean isNull(Integer num){
	    return num==null || num<1;
	}
	
	/**
	 * 判断Double是否为空(金额)
	 * */
	public static boolean isNull(Double num){
	    return num==null || num<1;
	}
	
	/**
	 *<p>方法说明: TODO 测试测试
	 **/
	public static void main(String[] args) {
		String n = " ";
		System.out.println(isNull(n));
	}
}

就像这样,大家还可以根据自己的需要继续添加;

转载于:https://my.oschina.net/u/3681868/blog/1568168

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值