实用代码块记录4

1.判断字符串是否为null或长度为0

public static boolean isStrEmpty(String str) {
        if (str == null || str.length() == 0) {
            return true;
        } else {
            return false;
        }
    }

2.判断数组是否为null或者长度为0

public static <T> boolean isArrayEmpty(T[] array) {
        if (getArraySize(array) == 0) {
            return true;
        } else {
            return false;
        }
    }

3.获取数组的长度

public static <T> int getArraySize(T[] array) {
        return array == null ? 0 : array.length;
    }

4.判断List是否为null或size = 0

public static <T> boolean isListEmpty(List<T> list) {
        if (getListSize(list) == 0) {
            return true;
        } else {
            return false;
        }
    }

5.获取List数据的size

public static <T> int getListSize(List<T> list) {
        return (list == null) ? 0 : list.size();
    }

6.判断Map是否为null或size = 0

public static <K, V> boolean isMapEmpty(Map<K, V> map) {
        if (getMapSize(map) == 0) {
            return true;
        } else {
            return false;
        }
    }

7.获取Map数据的size

public static <K, V> int getMapSize(Map<K, V> map) {
        return (map == null) ? 0 : map.size();
    }

8.判断Set是否为null或size = 0

public static <E> boolean isSetEmpty(Set<E> set) {
        if (getSetSize(set) == 0) {
            return true;
        } else {
            return false;
        }
    }

9.获取Set数据的size

public static <E> int getSetSize(Set<E> set) {
        return set == null ? 0 : set.size();
    }

10.判断字符串是否为纯数字

public static boolean isNumber(String str) {
        if (isStrEmpty(str)) {
            return false;
        }
        return str.matches("[0-9]+");
    }

11.判断字符串是否为纯字母

public static boolean isLetter(String str) {
        if (isStrEmpty(str)) {
            return false;
        }
        return str.matches("[a-zA-Z]+");
    }

12.判断是否为邮箱格式

   public static boolean isEmailAddress(String str) {
        String match = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        if (isStrEmpty(str)) {
            return false;
        }
        return str.matches(match);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值