java通用的方法整理

判断字符串是否为空

public static boolean IsEmpty(String str){
    if (str == null){
               return true;       
        }
    if ("".equals(str)){
               return true;
        }
    return false;
}        

判断字符串str是否包含s1

public static boolean IsHas(String str,String s1){
    if(IsEmpty(str)){
        return false;
    }
    if(IsEmpty(s1)){
        return false;
    }
    if(str.indexOf(s1) == -1){
        return false;
    }
    return true;
}

判断list 是否为空

public static boolean IsEmptyList(List lt){
    if (lt == null){
        return true;
    }
    if (lt.size() == 0){
        return true;
    }
    return false;
}

判断字符串是否相等

public static boolean Equals(String str1,String str2){
    if(IsEmpty(str1)){
        if(IsEmpty(str2)){
            return true;
        }else{
            return false;
        }
    }
    if (str1.equals(str2)){
        return true;
    }
    return false;
}

俩个日期间隔的天数

    public static long MakeDateLength(String Date1, String Date2){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try{
            Date d1 = df.parse(Date1);
            Date d2 = df.parse(Date2);
            long t1 = d1.getTime();
            long t2 = d2.getTime();
            long t = t1 - t2;
            t /= 1000*60*60*24;
            return t;
        }
        catch (ParseException e){
        }
        return 0;
    }

通过给定日期推算新的日期,afterDay为经过的天数

public static String GetDateAfter(String date,int afterDay){
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try{
        Date d = df.parse(date);
        long nTime = d.getTime();
        long aTime = ((long) afterDay) * 24 * 60 * 60 * 1000;
        d.setTime(nTime + aTime);
        return df.format(d);
    }
    catch (ParseException e){
    }
    return "";
}
原文地址:https://www.cnblogs.com/liuxing0705/p/4505633.html