zoukankan      html  css  js  c++  java
  • 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 "";
    }
  • 相关阅读:
    推流当中自适应码率的策略
    使用python实现人脸检测<转载>
    acm.njupt 1001-1026 简单题
    fedora 系统安装后常用设置
    一个普普通通的计算机研究生找工作的感悟
    一个简单的爬虫程序
    HDU 1005 Number Sequence
    【StatLearn】统计学习中knn算法的实验(1)
    SQL描述(2)
    连续点击返回键,退出应用程序
  • 原文地址:https://www.cnblogs.com/liuxing0705/p/4505633.html
Copyright © 2011-2022 走看看