java通用的方法整理
2024-10-19 04:34:58
判断字符串是否为空
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 "";
}
最新文章
- MVC 传值
- hdu 5749 Colmerauer
- Dive into python学习笔记
- /usr/bin/env: node: no such file or directory
- 页面中插入百度地图(使用百度地图API)
- [2014-08-24]为 Xamarin Studio 创建的 Asp.Net Mvc 项目配置 gitignore
- layui select使用问题
- 2.7 json 模块
- 利用Crosstool-ng制作交叉编译工具链
- react 的双向数据绑定
- JS 调试中常见的报错的解决办法
- [HAOI2010]最长公共子序列(LCS+dp计数)
- emoji表情softbank和unicode不兼容解决方案
- Linux服务安装配置总结
- luoguP4709 信息传递 置换 + 多项式exp
- Python中StringIO和BytesIO
- JSPatch动态更新APP
- 产品思维&;技术思维&;工程思维
- bzoj 3309 反演
- 第十六篇:初探IO复用