|
Commons Lang 扩展了标准 java.lang api增加了串操作思路方法、基本数值思路方法、对象反射、创建和串行化以及 属性它还包含个可继承 enum 类型、对多种嵌套 Exception 类型支持、对java.util.Date 增强以及用于构建思路方法实用例如 hashCode、toString 和 equals我发现 Commons Lang对应用很多方面都很有帮助通过使用 Commons Lang您将编写更少代码从而可以更快地交付缺陷更少。但也有不足之处,这个问题可以解决,因为它是开源项目,发现不足之处,可以获取源码进行修正或者提交Bug。
官方网址:http://commons.apache.org/proper/commons-lang/
String manipulation (字符串操作)
一系列操作字符串的工具类,包括StringUtils, StringEscapeUtils, RandomStringUtils, Tokenizer, WordUtils,其中最常用的是StringUtils。
主要处理char和Characters,包括CharSetUtils, CharSet, CharRange, CharUtils。其中CharSetUtils比较常用,其功能主要对字符串进行设置与操作。
虚拟机交互工具类有SystemUtils, CharEncoding。SystemUtils是个非常简单的工具类,通过这个工具类很方便获取到你所在的系统平台信息。
CharEncoding与Java环境的字符集进行交互,能使用或者查看此环境中支持的字符集。
序列化工具类SerializationUtils, SerializationException。
Assorted Functions (其余功能)
其余功能的工具类ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils
其他工具类BitField, Validate
时间管理工具类
1. DateFormatUtils - 时间格式化工具类
2. DateUtils - 时间工具类
3. DurationFormatUtils - 用于计算时间间隔的工具类
format常量如下:
下面是如何使用该工具类的例子:
Calendar calendar = Calendar.getInstance();
Date endDate = calendar.getTime();
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
Date startDate = calendar.getTime();
String startDateStr = DateFormatUtils.format(startDate,
"yyyy-MM-dd HH:mm:ss");
String endDateStr = DateFormatUtils.format(endDate,
"yyyy-MM-dd HH:mm:ss");
String durationByMonth = DurationFormatUtils.formatPeriod(
startDate.getTime(), endDate.getTime(), "M");
String durationByDay = DurationFormatUtils.formatPeriod(
startDate.getTime(), endDate.getTime(), "d");
System.out.println("start time : " + startDateStr);
System.out.println("end time : " + endDateStr);
System.out.println("时间间隔 (月): " + durationByMonth);
System.out.println("时间间隔 (日): " + durationByDay);
4. FastDateFormat -
|
|
|