Truncating Date Objects(不知如何翻译,),使用 DateUtils.truncate() 直接看例子吧 import org.apache.commons.lang.time.DateUtils;import org.apache.commons.lang.time.FastDateFormat;import org.apache.commons.lang.time.DateFormatUtils;FastDateFormat dtFormat = DateFormatUtils.ISO_DATETIME_FO ...
日期取整(日期精度调节,如调节至秒/分等)问题提出:日期取整解决方法:使用DateUtils。DateUtils.round() can round to almost every Calender field, 包括Calender.YEAR,Calendar.SECOND,Calendar.MINUTE,Calendar.HOUR,Calendar.DAY_OF_MONTH,Calendar.MONTH.使用举例:  import org.apache.commons.lang.time.FastDateFormat;import org ...
格式化日期问题提出:SimpleDateFormat是非线程安全的,而您又需要一个ISO格式的日期。解决方法:使用FastDateFormat或者使用DateFormatUtils提供的静态FastDateFormat实例,它提供了一些格式化日期的线程安全的方法。使用举例:     Date now = new Date();    String isoDT = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FOR ...
从多维数组里构造一个map问题提出:需要构造一个和数组等价的map解决方法:使用ArrayUtils.toMap() 方法构造一个和二维数组(object[])等价的map。使用举例: import org.apache.commons.lang.ArrayUtils;Object[] weightArray =     new Object[][] { {"H" , new Double( 1.007)},   & ...
在对象数组(Object Arraysand )和基本类型数组(Primitive Arrays)间转换问题提出:需要在对象数组和基本类型数组间进行转换解决方法:使用ArrayUtils.toObject()和ArrayUtils.toPrimitive()方法。使用举例: import org.apache.commons.lang.ArrayUtils;long[] primitiveArray = new long[] { 12, 100, 2929, 3323 };Long[] ...
clone并倒转一个数组问题提出:需要clone并倒转一个数组中的内容解决方法:使用ArrayUtils.clone() 和 ArrayUtils.reverse() 方法使用举例: import org.apache.commons.lang.ArrayUtils;    long[] array = { 1, 3, 2, 3, 5, 6 };long[] reversed = ArrayUtils.clone(& ...
打印一个数组中的内容问题提出:如果需要打印数组中的内容解决方法:使用ArrayUtils.toString()方法。使用举例:     int[] intArray = new int[] { 2, 3, 4, 5, 6 };    int[] multiDimension = new int[][] { { 1, 2, 3 } ...
问题提出:需要快速实现compareTo()方法解决方法:使用CompareToBuilder提供的compareTo()方法。同样的CompareToBuilder也使用了反射机制。以下代码提供了一个compareTo()方法,用于比较两个对象所有的非static和非transient成员变量。 import org.apache.commons.lang.builder.CompareToBuilder;// Build a compareTo function from reflection public&n ...
2.自动化hashCode()和equals()  问题产生:当需要自动实现hashCode()和equals()方法  解决方法:使用EqualsBuilder和HashCodeBuilder   使用举例:  import org.apache.commons.lang.builder.HashCodeBuilder;import org.apache.commons.lang.builder.EqualsBuilder;public class PoliticalCandidate {  ...
本笔记是在阅读Jakarta Commons Cookbook时所留下的。1.使用ReflectionToStringBuilder 或者ToStringBuilder 自动产生toString()的内容。   使用举例:假设有一个表征校长候选人信息的javabean-PoliticalCandidate。   public class PoliticalCandidate {    private String lastName;  &nbs ...