apache常用的工具类
来源:互联网 发布:程序员离职原因 编辑:程序博客网 时间:2024/05/22 11:30
1.判断一个list是否为空
List<Item> itemList = itemService.listByOrderIdList(orderIdList);CollectionUtils.isNotEmpty(itemList)2.获取不同精度的时间,参数还可以为:Calendar.HOUR_OF_DAY,Calendar.MINUTE,Calendar.SECOND等
Date itemDate = null;itemDate = DateUtils.truncate(item.getUpdateTime(), Calendar.DATE);3.从一个entity中把属性复制进另外一个entity中
StuForm form = new StuForm("lee", 18, 1, new Date(), true);Stu stu = new Stu(); BeanUtils.copyProperties(form, stu);System.out.println(stu.toString());4.文件操作工具类
//1.读取Stream //标准代码: InputStream in = new URL( "http://jakarta.apache.org" ).openStream(); try { InputStreamReader inR = new InputStreamReader( in ); BufferedReader buf = new BufferedReader( inR ); String line; while ( ( line = buf.readLine() ) != null ) { System.out.println( line ); } } finally { in.close(); } //使用IOUtils InputStream in = new URL( "http://jakarta.apache.org" ).openStream(); try { System.out.println( IOUtils.toString( in ) ); } finally { IOUtils.closeQuietly(in); } //2.读取文件 File file = new File("/commons/io/project.properties"); List lines = FileUtils.readLines(file, "UTF-8"); //3.查看剩余空间 long freeSpace = FileSystemUtils.freeSpace("C:/");5.首字母大写
String str1 = "person";str1 = StringUtils.capitalize(str1);System.out.println(str1); //Person6.取得字符串的缩进
使用函数: StringUtils.abbreviate(testString,width)和StringUtils.abbreviate(testString,offset,width)
函数介绍:在给定的width内取得testString的缩写,当testString的长度小于width则返回原字符串.
例程:
String test = "This is a test of the abbreviation."; String test2 = "Test"; System.out.println( StringUtils.abbreviate( test, 15 ) ); System.out.println( StringUtils.abbreviate( test, 5,15 ) ); System.out.println( StringUtils.abbreviate( test2, 10 ) );输出如下:This is a te......is a test...Test7.取得某字符串在另一字符串中出现的次数
使用函数:StringUtils.countMatches(testString,seqString)
函数介绍:取得seqString在testString中出现的次数,未发现则返回零
例程:
System.out.println(StringUtils.countMatches( "Chinese People", "e"));输出:48.是否都是由字母组成
public static boolean isAlpha(String str); 只由字母组成 public static boolean isAlphaSpace(String str); 只有字母和空格组成 public static boolean isAlphanumeric(String str);只由字母和数字组成 public static boolean isAlphanumericSpace(String str);只由字母数字和空格组成 public static boolean isNumeric(String str);只由数字组成 public static boolean isNumericSpace(String str);只由数字和空格组成
阅读全文
0 0
- apache常用的工具类
- Apache Commons-io 常用的操作文件工具类
- 常用Apache Commons工具类备忘
- 常用Apache Commons工具类备忘
- Apache的IO工具类
- 常用代码备忘录(封装 Apache Commons 的 DbUtils 实现的数据库操作工具类)-DBUtil.java
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtil(StringUtil工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- 常用的工具类
- 常用的工具类
- 常用的工具类
- 常用的工具类
- org.apache.commons.lang3.StringUtils工具类常用方法
- org.apache.commons-io文件工具类FileUtils常用操作
- 《模仿游戏》——“计算机之父”的传奇人生
- Docker Tips
- okhttp/Retrofit-rxJava加入数字证书支持HTTPS 实现单向及双向验证
- Codeforces-258D:Little Elephant and Broken Sorting(概率DP)
- curl:<1> Protocol "'http" not supported or disabled in libcurl
- apache常用的工具类
- 数据结构-C语言 单链线性表实现归并 C=A∪B
- ubuntu16.04安装teamviewer12依赖包解决
- BZOJ 4726 Sabota? (树型dp)
- sdnu1042购物
- Java基准测试 JMH
- 初识react native 练习记录
- Tensorflow 查看变量的值
- 挑战程序竞赛系列(94):3.6凸包(5)