字符串工具类

public class ObjectUtils {

   /**
    * 判断数组是否为空
    * @param target
    * @return
    */
   public static boolean isEmpty(Object[] target) {
      return target == null || target.length == 0 ;
   }

   public static boolean isNotEmpty(Object[] target) {
      return target != null && target.length > 0;
   }

   /**
    * 判断对象是否为空
    *
    * @param target
    * @return
    */
   public static boolean isEmpty(Object target) {
      if (target instanceof Collection) {
         Collection collection = (Collection)target;
         return collection == null || collection.size() == 0;
      } else if (target instanceof Map) {
         Map map = (Map)target;
         return map == null || map.size() == 0;
      }
      return target == null || target.toString().trim().length() == 0;
   }

   public static boolean isNotEmpty(Object target) {
      if (target instanceof Collection) {
         Collection collection = (Collection) target;
         return collection != null && collection.size() > 0;
      } else if (target instanceof Map) {
         Map map = (Map) target;
         return map != null && map.size() > 0;
      }
      return target != null && target.toString().trim().length() > 0;
   }



   /**
    * 将字符串转换成数组
    * @param str
    * @return
    */
   public static String[] spilt(String str) {
      if (str == null)
         throw new NullPointerException("str can not be null");
      return str.split(",");
   }

   public static String[] spilt(String str, String separator) {
      if (str == null)
         throw new NullPointerException("str can not be null");
      return str.split(separator);
   }

   /**
    * 将首字母变成小写
    * @param keyName
    * @return
    */
   public static String toLowerCaseFirst(String keyName){
      return keyName.substring(0, 1).toLowerCase();
   }

   /**
    * 将首字母变成大写
    * @param keyName
    * @return
    */
   public static String totoUpperCaseFirst(String keyName) {
      return keyName.substring(0, 1).toUpperCase() + keyName.substring(1, keyName.length());
   }

   /**
    * 生成年月日字符串
    * @return
    */
   public static String generateFileByTime() {
      DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      return format.format(new Date()).replaceAll("-", "/") + "/";
   }

   /**
    * 生成时分秒字符串
    * @return
    */
   public static String generateFileBySecond() {
      DateFormat format = new SimpleDateFormat("hh-mm-ss");
      return format.format(new Date()).replaceAll("-", "");
   }

   public static String generateUuId() {
      return UUID.randomUUID().toString().replaceAll("-", "");
   }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值