字符串和对象判空工具类

/*
        Copyright  DR.YangLong

        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
*/
package com.quancai.erp.utils;


/**
 * functional describe:字符串相关工具类
 */
public class StringUtilTools {


    /**
     * 判断字符串是不是NULL或是空字符串,如果是,返回true,不是false
     *
     * @param str 待判断字符串
     * @return true/false
     */
    public static boolean isNullOrEmpty(final String str) {
        return str == null || "".equals(str);
    }

    /**
     * 判断字符串对象是不是NULL或空,如果是,返回true,不是false
     * @param str 字符串对象
     * @return true/false
     */
    public static boolean isNullOrEmpty(final Object str){
        return str==null||"".equals(str.toString());
    }


    /**
     * 对比2个对象的内容是否一致
     * @param ob1 对象1
     * @param ob2 对象2
     * @return true/false
     */
    public static boolean equalObject(Object ob1,Object ob2){
        return !(ob1==null||ob2==null)&&ob1.equals(ob2);
    }

    /**
     * 对比2个String对象的内容是否一致,忽略大小写
     * @param ob1 对象1
     * @param ob2 对象2
     * @return true/false
     */
    public static boolean equalStringObjectIgnoreCase(Object ob1,Object ob2){
        return !(ob1==null||ob2==null)&&(ob1.toString().equalsIgnoreCase(ob2.toString()));
    }

    /**
     *
     * @param array 数组
     * @param surffix 分割符号
     * @return
     */
    public static String array2String(final String[] array,final String surffix){
        StringBuilder builder=new StringBuilder();
        for(int i=0;i<array.length;i++){
            if(i==array.length-1){
                builder.append(array[i]);
            }
            else {
                builder.append(array[i]).append(surffix);
            }
        }
        return builder.toString();
    }

    /**
     * 调用对象的toString方法,返回对象的字符串,如果是NULL返回null字符串
     * @param o 对象
     * @return String
     */
    public static String wrapperNull(Object o){
        if(o==null){
            return "null";
        }
        return o.toString();
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值