不要想着一次就可以写出完美的代码,多思考多修改才能更接近完美。
org.apache.commons.lang3.StringUtils
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8</version>
</dependency>
-----非空判断-----
public static boolean isEmpty(CharSequence cs)
/**
*参数为【null或""】都会返回true
*/
StringUtils.isEmpty(null); //true
StringUtils.isEmpty(""); //true
StringUtils.isEmpty(" "); //false
StringUtils.isEmpty("abc"); //false
public static boolean isNotEmpty(CharSequence cs)
/**
*参数不为【null或""】才会返回true
*/
StringUtils.isNotEmpty(null); //false
StringUtils.isNotEmpty(""); //false
StringUtils.isNotEmpty(" "); //true
StringUtils.isNotEmpty("abc"); //true
public static boolean isAnyEmpty(CharSequence… css)
/**
*任意一个参数为[null或""]都会返回true
*/
StringUtils.isAnyEmpty(null,"aaa","bbb"); //true
StringUtils.isAnyEmpty("","aaa","bbb"); //ture
StringUtils.isAnyEmpty(" ","aaa","bbb"); //false
StringUtils.isAnyEmpty("aaa","bbb","ccc"); //false
public static boolean isNoneEmpty(CharSequence… css)
/**
*所有参数都不是【null或“”】才会返回true
*/
StringUtils.isNoneEmpty(null,"aaa","bbb"); //false
StringUtils.isNoneEmpty("","aaa","bbb"); //false
StringUtils.isNoneEmpty(" ","aaa","bbb"); //true
StringUtils.isNoneEmpty("aaa","bbb","ccc"); //true
-----非空判断-----
public static boolean isBlank(CharSequence cs)
/**
*参数为[null或“”或" "]都会返回true
*/
StringUtils.isBlank(null); //true
StringUtils.isBlank(""); //true
StringUtils.isBlank(" "); //true
StringUtils.isBlank("abc"); //false
public static boolean isNotBlank(CharSequence cs)
/**
*参数不为【null或""或" "】才会返回true
*/
StringUtils.isNotBlank(null); //false
StringUtils.isNotBlank(""); //false
StringUtils.isNotBlank(" "); //false
StringUtils.isNotBlank("abc"); //true
public static boolean isAnyBlank(CharSequence… css)
/**
*任意一个参数为【null或""或" "】都会返回true
*/
StringUtils.isAnyBlank(null,"aaa","bbb"); //true
StringUtils.isAnyBlank("","aaa","bbb"); //true
StringUtils.isAnyBlank(" ","aaa","bbb"); //true
StringUtils.isAnyBlan