Commons-lang API介绍
4.1 Commons-lang API介绍
4.1.1 StringUtils
4.1.2 StringEscapeUtils
4.1.3 ArrayUtils
4.1.4 DateUtils
4.1.5 DateFormatUtils
4.1.6 RandomUtils
4.1.7 NumberUtils
4.1.8 FieldUtils
4.1.9 CharUtils
4.1.10 BooleanUtils
4.1.11 ExceptionUtils
1 StringUtils方法介绍
StringUtils是提供字符串操作的工具类。提供的方法如下:
1 public static boolean isEmpty(String str);
说明:
如果参数str为NULL或者str.length() == 0 返回true
对比:JDK 中类String的方法public boolean isEmpty()
此方法通过判断私有变量count是否等于0来进行判断。
StringUtils.isEmpty(null) = true |
StringUtils.isEmpty("") = true |
StringUtils.isEmpty(" ") = false |
StringUtils.isEmpty(" ") = false |
StringUtils.isEmpty("aa") = false |
StringUtils.isEmpty(" aaa ") = false |
2 public static boolean isNotEmpty(String str)
说明:
判断给定参数是否不为空,其实现方式利用了方法一: !isEmpty(str);
对比:JDK中String类无此方法。
StringUtils.isNotEmpty(null);//false
StringUtils.isNotEmpty("");//false
StringUtils.isNotEmpty(" ");//true
StringUtils.isNotEmpty(" ");//true
StringUtils.isNotEmpty("aa");//true
StringUtils.isNotEmpty(" aaa ");//true
3 public static boolean isBlank(String str);
说明:
如果参数str为NULL或者其长度等于0,又或者其由空格组成,那么此方法都返回true。
对比:JDK中String类无此方法。
System.out.println(StringUtils.isBlank(null));//true
System.out.println(StringUtils.isBlank(""));//true
System.out.println(StringUtils.isBlank(" "));//true
System.out.println(StringUtils.isBlank(" "));//true
System.out.println(StringUtils.isBlank("\n\t"));//true
System.out.println(StringUtils.isBlank("aaa"));//false
System.out.println(StringUtils.isBlank(" aa "));//false
4 public static boolean isNotBlank(String str);
说明:利用方法三实现。
5 public static String
trim(String str);
说明:
去除字符串开头和结尾处的空格字符。如果参数str为null,则返回null.
对比:
利用JDK中String类的trim()方法。
//去空格.Null返回null~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.out.println(StringUtils.trim(null));
//去空格,将Null和"" 转换为Null
System.out.println(StringUtils.trimToNull(""));
//去空格,将NULL 和 "" 转换为""
System.out.println(StringUtils.trimToEmpty(null));
6 public static String
stripStart(String str, String stripChars);
说明:
去掉str前端的在stripChars中的字符
//如果第二个参数为null只去前面空格(否则去掉字符串前面一样的字符,到不一样为止)
System.out.println(StringUtils.stripStart("ddsuuu ", "d"));
7 public static String
stripEnd(String str, String stripChars);
说明:
去掉str末端的在stripChars中的字符
//如果第二个参数为null只去后面空格,(否则去掉字符串后面一样的字符,到不一样为止)
System.out.println(StringUtils.stripEnd("dabads", "das"));
//如果第二个参数为null去空格(否则去掉字符串2边一样的字符,到不一样为止)
System.out.println(StringUtils.strip("fsfsdf", "f"));
//检查是否查到,返回boolean,null返回假
System.out.println(StringUtils.contains("sdf", "dg"));
//检查是否查到,返回boolean,null返回假,不区分大小写
System.out.println(StringUtils.containsIgnoreCase("sdf", "D"));
//检查是否有含有空格,返回boolean
System.out.println(StringUtils.containsWhitespace(" d"));
8 public static int ordinalIndexOf(String
str, String searchStr, int ordinal)
说明:
返回字符串search在字符串str中第ordinal次出现的位置。
如果str=null或searchStr=null或ordinal<=0则返回-1.
//从指定位置(三参数)开始查找,本例从第2个字符开始查找k字符
System.out.println(StringUtils.indexOf("akfekcd中华", "k", 2));
//未发现不同之处
System.out.println(StringUtils.ordinalIndexOf("akfekcd中华", "k", 2));
9. StringUtils.defaultIfEmpty(String
str, String defalutValue)
如果字符串为""或者 null 则替换成参数2中的字符串:
System.out.println("1:
" + StringUtils.defaultIfEmpty("", "a"));//1: a
System.out.println("2: " + StringUtils.defaultIfEmpty("\n\t", "a"));//2:
System.out.println("3: " + StringUtils.defaultIfEmpty("", "a"));//3: a
System.out.println("4: " + StringUtils.defaultIfEmpty(" ", "a"));//4:
System.out.println("5: " + StringUtils.defaultIfEmpty("aaa", "a"));//5: aaa
System.out.println("6: " + StringUtils.defaultIfEmpty(" aaa ", "a"));//6: aaa
System.out.println("7: " + StringUtils.defaultIfEmpty(null, "a"));//7: a
10. StringUtils.defaultString(String
str, String defaultValue)
和9相似:
System.out.println("1: " + StringUtils.defaultString(null, "a"));//1: a
System.out.println("2: " + StringUtils.defaultString("", "a"));//2:
System.out.println("3: " + StringUtils.defaultString(" ", "a"));//3:
System.out.println("4: " + StringUtils.defaultString("\n\t", "a"));//4:
System.out.println("5: " + StringUtils.defaultString("aa", "a"));//5: aa
System.out.println("6: " + StringUtils.defaultString(" aaa", "a"));//6: aaa
11. StringUtils.capitalize(String
str)
首字母大写
System.out.println(StringUtils.capitalize("xxxx"));//Xxxx
System.out.println(StringUtils.capitalize("Xxxx"));//Xxxx
12. StringUtils.remove(String
str, String removeStr)
从str中去除removeStr
System.out.println(StringUtils.remove("abcd", "ab"));//cd
System.out.println(StringUtils.remove("abcd", "ad"));//abcd
13. StringUtils.countMatches(String
str, String find)
计算字符串在另一个字符串中出现的次数:
int nCount = StringUtils.countMatches("UPDATE tb_table SET xx=?,xyz=?, sss=? WHERE id=?", "?");//nCount
= 4
http://www.cnblogs.com/jifeng/archive/2012/08/05/2623767.html
4.1.2 StringEscapeUtils
StringEscapeUtils这个类里提供了很多转义的方法,比如可以转成json、xml、html等格式。
1.escapeJava/unescapeJava 把字符串转为unicode编码
package com.kungeek.tip; import org.apache.commons.lang.StringEscapeUtils; public class test { public static void main(String args[]) {
String sql = "1' or '1'='1";
// 防SQL注入 防SQL注入:1'' or ''1''=''1
System.out.println("防SQL注入:" + StringEscapeUtils.escapeSql(sql)); // 转义成Unicode编码 转成Unicode编码:\u9648\u78CA\u5174
String unicode="陈磊兴";
String esc_unicode=StringEscapeUtils.escapeJava(unicode);
String unesc_unicode=StringEscapeUtils.unescapeJava(esc_unicode);
System.out.println("转成Unicode编码:" + esc_unicode);
System.out.println("反转成Unicode编码:" + unesc_unicode); String html="<font>chen磊 xing</font>";
String esc_html=StringEscapeUtils.escapeHtml(html);
String unesc_html=StringEscapeUtils.unescapeHtml(esc_html);
// 转义HTML
System.out.println("转义HTML:" + esc_html);
// 反转义HTML
System.out.println("反转义HTML:" + unesc_html); String xml="<name>陈磊兴</name>";
String esc_xml=StringEscapeUtils.escapeHtml(xml);
String unesc_xml=StringEscapeUtils.unescapeXml(esc_xml);
// 转义xml 转义XML:
System.out.println("转义XML:" + esc_xml);
// 转义xml 反转义XML:
System.out.println("反转义XML:" +unesc_xml ); } }
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAACsCAIAAAACHsnzAAAgAElEQVR4nO2d+XMcyXXn+++xQmGHwr+grR/WQcja/WHDGxu7EdpdWaFwSEVTo+GMrBiFdsPjtWx55B1JRg+H13B438cQAK8CwCGJGQ4PkASJBoiTBQIgcREAcd8Awdwf6nqZ+TLr6kYfeJ+oILurK7NeHvXNl1mZiVRDB2OMsfGzZz/8/p7z95jLi5ElOuiggw46SvRINXQw1vHxng93NI8ziCpA06MOOpoedTCCIIgiJtVw/uM9H378XPpBlvX+F6MPH3c9fNzV/2KUDjsrClBiBEEQIUjt2b3jrOS2M0ncB16+am7pGXj5ig54NLf0FKLUCIIgAkg1dDgD7g38SIMg7i1tz14MvqJDPlranhWo7AiCIJSkXE2/1/Dh9/d8+LH3A1T2weHx1vbeweFxOuSjtb23QGVHEAShJKX6AYr7086+4ZEJOlTH086+zSwzgiCIQEKJe0f3wMjoazpUR0f3AMy6tidXBvsfvexrHuh73Nfb0mtln/W0dnW3dXS1t3V2trZ3dfQ8X1lZzX/hEgSxdQkl7l09L16NTQrHzeaX3//wzvf+QXn853+629w5Kgcsv6Or5wXMumxz7fjK+urq0tLK8uLy8vzS8uzi8vTC8uT8cs/g7Pjcct/weHPbs9n5pfyXb9Gx0naoqe5MT9Ol3uYr032NhTaH2KKculZbaBPyTihx77Fejo1PCcdffHD7r40//Jef/l51/PX2P/6HX38tB9zM43HVttTPruT7Lj3WS5h12ebasZU3bzbers4vTt++O/r54fHL1+YmZ+dWNrpezEwtv3m99KZ3eLLn+Uhuy3ImW32wcSD8+c1npe3QQteFjZWejZWelwM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AAASUVORK5CYII=" alt="" />
4.1.3 ArrayUtils
package chongqingyusp; import java.util.Map; import org.apache.commons.lang.ArrayUtils; public class test { public static void main(String[] args) { // 1.打印数组
String a=ArrayUtils.toString(new int[] { 1,4, 2, 3 });// {1,4,2,3}
String a1=ArrayUtils.toString(new Integer[] { 1, 4, 2, 3 });// {1,4,2,3}
String a2=ArrayUtils.toString(null, "I'm nothing!");// I'm nothing! System.out.println("a----------"+a);
System.out.println("a1----------"+a1);
System.out.println("a2----------"+a2);
System.out.println("-----------------------------------------");
// 2.判断两个数组是否相等,采用EqualsBuilder进行判断
// 只有当两个数组的数据类型,长度,数值顺序都相同的时候,该方法才会返回True
// 2.1 两个数组完全相同
boolean b=ArrayUtils.isEquals(new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 });// true
// 2.2 数据类型以及长度相同,但各个Index上的数据不是一一对应
boolean b1=ArrayUtils.isEquals(new int[] { 1, 3, 2 }, new int[] { 1, 2, 3 });//false
// 2.3 数组的长度不一致
boolean b2=ArrayUtils.isEquals(new int[] { 1, 2, 3, 3 }, new int[] { 1, 2, 3 });//false
// 2.4 不同的数据类型
boolean b3=ArrayUtils.isEquals(new int[] { 1, 2, 3 }, new long[] { 1, 2, 3 });// false
boolean b4=ArrayUtils.isEquals(new Object[] { 1, 2, 3 }, new Object[] { 1, (long) 2, 3 });// false
// 2.5 Null处理,如果输入的两个数组都为null时候则返回true
boolean b5=ArrayUtils.isEquals(new int[] { 1, 2, 3 }, null);// false
boolean b6=ArrayUtils.isEquals(null, null);// true System.out.println("b----------"+b);
System.out.println("b1----------"+b1);
System.out.println("b2----------"+b2);
System.out.println("b3----------"+b3);
System.out.println("b4----------"+b4);
System.out.println("b5----------"+b5);
System.out.println("b6----------"+b6);
System.out.println("-----------------------------------------"); // 3.将一个数组转换成Map
// 如果数组里是Entry则其Key与Value就是新Map的Key和Value,如果是Object[]则Object[0]为KeyObject[1]为Value
// 对于Object[]数组里的元素必须是instanceof Object[]或者Entry,即不支持基本数据类型数组
// 如:ArrayUtils.toMap(new Object[]{new int[]{1,2},new int[]{3,4}})会出异常
Map c=ArrayUtils.toMap(new Object[] { new Object[] { 1, 2 }, new Object[] { 3, 4 } });// {1=2,
// 3=4}
Map c1=ArrayUtils.toMap(new Integer[][] { new Integer[] { 1, 2 }, new Integer[] { 3, 4 } });// {1=2,
// 3=4} System.out.println("c----------"+c);
System.out.println("c1----------"+c1);
System.out.println("-----------------------------------------"); // 4.拷贝数组
int[] d=ArrayUtils.clone(new int[] { 3, 2, 4 });// {3,2,4}
System.out.println("d----------"+ArrayUtils.toString(d));
System.out.println("-----------------------------------------"); // 5.截取数组
int[] e=ArrayUtils.subarray(new int[] { 3, 4, 1, 5, 6 }, 2, 4);// {1,5}
System.out.println("e----------"+ArrayUtils.toString(e));
// 起始index为2(即第三个数据)结束index为4的数组
int[] e1=ArrayUtils.subarray(new int[] { 3, 4, 1, 5, 6 }, 2, 10);// {1,5,6}
// 如果endIndex大于数组的长度,则取beginIndex之后的所有数据
System.out.println("e1----------"+ArrayUtils.toString(e1));
System.out.println("-----------------------------------------"); // 6.判断两个数组的长度是否相等
boolean f=ArrayUtils.isSameLength(new Integer[] { 1, 3, 5 }, new Long[] { 2L, 8L, 10L });// true
System.out.println("f----------"+f);
System.out.println("-----------------------------------------"); // 7.获得数组的长度
int g=ArrayUtils.getLength(new long[] { 1, 23, 3 });//
System.out.println("g----------"+g);
System.out.println("-----------------------------------------"); // 8.判段两个数组的类型是否相同
boolean h=ArrayUtils.isSameType(new long[] { 1, 3 }, new long[] { 8, 5, 6 });// true
boolean h1=ArrayUtils.isSameType(new int[] { 1, 3 }, new long[] { 8, 5, 6 });// false
System.out.println("h----------"+h);
System.out.println("h----------"+h1);
System.out.println("-----------------------------------------"); // 9.数组反转
int[] array =new int[] { 1, 2, 5 };
ArrayUtils.reverse(array);// {5,2,1}
System.out.println("i----------"+ArrayUtils.toString(array));
System.out.println("-----------------------------------------"); // 10.查询某个Object在数组中的位置,可以指定起始搜索位置,找不到返回-1
// 10.1 从正序开始搜索,搜到就返回当前的index否则返回-1
int j=ArrayUtils.indexOf(new int[] { 1, 3, 6 }, 6);//
int j1=ArrayUtils.indexOf(new int[] { 1, 3, 6 }, 2);// -1
// 10.2 从逆序开始搜索,搜到就返回当前的index否则返回-1
int j2=ArrayUtils.lastIndexOf(new int[] { 1, 3, 6 }, 6);// System.out.println("j----------"+ArrayUtils.toString(j));
System.out.println("j1----------"+ArrayUtils.toString(j1));
System.out.println("j2----------"+ArrayUtils.toString(j2));
System.out.println("-----------------------------------------"); // 11.查询某个Object是否在数组中
boolean k=ArrayUtils.contains(new int[] { 3, 1, 2 }, 1);// true
// 对于Object数据是调用该Object.equals方法进行判断
boolean k1=ArrayUtils.contains(new Object[] { 3, 1, 2 }, 1L);// false
System.out.println("k----------"+ArrayUtils.toString(k));
System.out.println("k1----------"+ArrayUtils.toString(k1));
System.out.println("-----------------------------------------"); // 12.基本数据类型数组与外包型数据类型数组互转
Integer[] l=ArrayUtils.toObject(new int[] { 1, 2 });// new Integer[]{Integer,Integer}
int[] l1=ArrayUtils.toPrimitive(new Integer[] { new Integer(1), new Integer(2) });// new int[]{1,2}
System.out.println("l----------"+ArrayUtils.toString(l));
System.out.println("l1----------"+ArrayUtils.toString(l1));
System.out.println("-----------------------------------------"); // 13.判断数组是否为空(null和length=0的时候都为空)
boolean m=ArrayUtils.isEmpty(new int[0]);// true
boolean m1=ArrayUtils.isEmpty(new Object[] { null });// false
System.out.println("m----------"+ArrayUtils.toString(m));
System.out.println("m1----------"+ArrayUtils.toString(m1));
System.out.println("-----------------------------------------"); // 14.合并两个数组
int[] o=ArrayUtils.addAll(new int[] { 1, 3, 5 }, new int[] { 2, 4 });// {1,3,5,2,4}
System.out.println("o----------"+ArrayUtils.toString(o));
System.out.println("-----------------------------------------"); // 15.添加一个数据到数组
int[] p=ArrayUtils.add(new int[] { 1, 3, 5 }, 4);// {1,3,5,4}
System.out.println("p----------"+ArrayUtils.toString(p));
System.out.println("-----------------------------------------"); // 16.删除数组中某个位置上的数据
int[] q=ArrayUtils.remove(new int[] { 1, 3, 5 }, 1);// {1,5}
System.out.println("q----------"+ArrayUtils.toString(q));
System.out.println("-----------------------------------------"); // 17.删除数组中某个对象(从正序开始搜索,删除第一个)
int[] r=ArrayUtils.removeElement(new int[] { 1, 3, 5 }, 3);// {1,5}
System.out.println("r----------"+ArrayUtils.toString(r));
System.out.println("-----------------------------------------"); } }
结果
a----------{1,4,2,3}
a1----------{1,4,2,3}
a2----------I'm nothing!
-----------------------------------------
b----------true
b1----------false
b2----------false
b3----------false
b4----------false
b5----------false
b6----------true
-----------------------------------------
c----------{1=2, 3=4}
c1----------{1=2, 3=4}
-----------------------------------------
d----------{3,2,4}
-----------------------------------------
e----------{1,5}
e1----------{1,5,6}
-----------------------------------------
f----------true
-----------------------------------------
g----------3
-----------------------------------------
h----------true
h----------false
-----------------------------------------
i----------{5,2,1}
-----------------------------------------
j----------2
j1-----------1
j2----------2
-----------------------------------------
k----------true
k1----------false
-----------------------------------------
l----------{1,2}
l1----------{1,2}
-----------------------------------------
m----------true
m1----------false
-----------------------------------------
o----------{1,3,5,2,4}
-----------------------------------------
p----------{1,3,5,4}
-----------------------------------------
q----------{1,5}
-----------------------------------------
r----------{1,5} -----------------------------------------
4.1.4 DateUtils
package com.kungeek.tip; import java.util.Calendar;
import java.util.Date; import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils; public class test { public static void main(String[] args) { Date now = new Date();
System.out.println("now:"+format(now)); //addYears
System.out.println("addYears:"+format(DateUtils.addYears(now, 1)));
//addMonths
System.out.println("addMonths:"+format(DateUtils.addMonths(now, 1)));
//addDays
System.out.println("addDays:"+format(DateUtils.addDays(now, 1)));
//addHours
System.out.println("addHours:"+format(DateUtils.addHours(now, 1)));
//addMinutes
System.out.println("addMinutes:"+format(DateUtils.addMinutes(now, 1)));
//addSeconds
System.out.println("addSeconds:"+format(DateUtils.addSeconds(now, 1)));
//addMilliseconds
System.out.println("addMilliseconds:"+DateUtils.addMilliseconds(now, 1));
//-------------------------------------------------------------------------------------
//isSameDay
System.out.println("isSameDay:"+DateUtils.isSameDay(now, DateUtils.addYears(now, 1)));
System.out.println("isSameDay:"+DateUtils.isSameDay(now, Calendar.getInstance().getTime()));
//-------------------------------------------------------------------------------------
//round
System.out.println("round:"+format(DateUtils.round(now, 1)));
System.out.println("round:"+format(DateUtils.round(now, 2)));
//truncate
System.out.println("truncate:"+format(DateUtils.truncate(now, 1)));
System.out.println("truncate:"+format(DateUtils.truncate(now, 2)));
//-------------------------------------------------------------------------------------
} private static String format(Date date){
return DateFormatUtils.format(date,"yyyy-MM-dd-HH:mm:ss");
} }
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVwAAADuCAIAAAD6ASixAAAXiElEQVR4nO2dy4GDuBZEO612QKTTDuFFQTJezWZCmK3fwjboSnX1wQgDPmfVltEXqZCEqv3zz7//3T/C7e/35/fv1jOLceidQz7zn5+fn2HsXJjb32+QyxLG4RH/nTuyKO6ziUS829/vT0BavaQ1vQLMF97+ft12uv39isjP8s0k10xXZOqurpnr9whMO4dT2lw7V7dJiZ9qUci16VY0lqF5HC6ooxvlNdQWF6Y6/9/f9+5MXNKWvN/uErpZbMrjkAqDHsa59DPDrDCsndjBmBsHR5jlNcHVr+Il1VnStrVtUgJReCP9bJRtROHRDxYP6/v9fgBRkFlVjoCCKDwHbfHmiAtMehnFSa4xab2qEVdnUduupApZUZhnpsFEKtA9Oyt6VGMcnkHj8PP7Nz5l+NkW4fVzrcfh5/fvz357nyX8p6EM93jON31RnkpVpW8LlUYxybmiEFfNFG7+EF8m79Dv3y3tZ68bYeJ64eHyIVzt2Jrlb4cTN14+pXe5UhSmENs68zVuAUSHe9YlyKAgCnKE2husU5DXiJuV5uHcrMKo8dukqcspUZAzqjCHuINP2fxEN2ZaMU3fiEYIZodh6YZXDvNsq1gGM40bB1GF3BArpu/MIRtnCqpq4oEmWyDJY9avSHKCegStp8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ExxzBgADogAABkQBAAyIAgAYEAUAMCAKAGA4lCiE7zV72atrU+sc0U1twyjwpVSeU+hHfV4b2KvXdUljr4ZDciBRCHkdGlrXXr2uSxp7NRwTIQr2dKC1US+1S4fHoYP5e3oSUUbxnRINbqUKe/VCC9baEWUg9mrYiuJMwdqoG+3Stp/droOe/79SjI5ITw+0OJlO9up1XdKLI2Kvhs9SJQrW7bDIGRkmYB7X1rpjSRPoa69uSK1nxPwzfJso8MVsKArhgJ7jNvj5xHaYifK2vXphamtHzKa2URT4YhaIQrg/UGmXHq+PR5Px9cnlw5zXOIS7ddvYq9d1SS+OiL0aPok+p/Cc5IsFaYtdOnbvzp+DuGFeYnVhdsssNr7YPnTm7dm38rWpdY6YBoZ7K/2iABzs8BIA9AdRAAADogAABkQBAAyIAgAYEAUAMBxKFBJjhA2NX/zd1rJOB+9S/XeLtcWoi+imtmEU+FIO5JL8lHU6SNc9ctBQjIqIeVPzNlHgezmQKIS8RmeLZ7ksCjK1+Dhw0UpVKEY54uo+6AVR4IvBOm2TlcahokdgoS+rxaoUnuzsFwUA67RX7bsZWsbHmTVgNBTDi+gXQxw7XzkKANbpKgd0cNV1aIkoPlZEzD/Dt4kCXwzW6drUFkcsLB/SiPlibBMFvhis07WpOWGtxaiJqALnlu8ZBQDrtFPzMLWqUwrVxaiLmAaGeyv9ogAc7PASAPQHUQAAA6IAAAZEAQAMiAIAGBAFADAgCgBgQBQAwIAoAIABUQAAA6IAAAZEAQAMiAIAGBAFADAgCgBgQBQAwIAoAIDh/weESeVBrvW1AAAAAElFTkSuQmCC" alt="" />
4.1.5 DateFormatUtils
与SUN的SimpleDateFormat相比,其主要优点是:线程安全。
对应于SimpleDateFormat的format()的方法,是DateFormatUtils 的format系列方法,常用的就是:
public static java.lang.String format (java.util.Date date, java.lang.String pattern);
DateFormatUtils定义了很多内置的固定日期格式,均为FastDateFormat类型,比如 ISO_DATE_FORMAT。使用 FastDateFormat的format()方法可以直接将日期格式化为内置的固定格式。
public java.lang.String format (java.util.Date date)
常用日期格式的格式化操作:
1: 以 yyyy-MM-dd 格式化:
DateFormatUtils.ISO_DATE_FORMAT.format(new
Date()): 2009-03-20
2:以 yyyy-MM-ddZZ 格式化:
DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.format(new Date()):
2009-03-20+08:00
3:以
yyyy-MM-dd'T'HH:mm:ss 格式化:
DateFormatUtils.ISO_DATETIME_FORMAT.format(new
Date()): 2009-03-20T22:07:01
4: 以 yyyy-MM-dd'T'HH:mm:ssZZ 格式化:
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new
Date()): 2009-03-20T22:07:01+08:00
5: 以 'T'HH:mm:ss 格式化:
DateFormatUtils.ISO_TIME_FORMAT.format(new
Date()): T22:07:01
6: 以 HH:mm:ss 格式化:
DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(new
Date()): 22:07:01
7: 以 HH:mm:ssZZ 格式化:
DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.format(new
Date()): 22:07:01+08:00
8: 以 'T'HH:mm:ssZZ 格式化:
DateFormatUtils.ISO_TIME_TIME_ZONE_FORMAT.format(new
Date()): T22:07:01+08:00
自定义日期格式的格式化操作:
1: 以 yyyy-MM-dd
HH:mm:ss 格式化Date对象:
DateFormatUtils.format(new Date(),
"yyyy-MM-dd HH:mm:ss"): 2009-03-20 22:24:30
2: 以 yyyy-MM-dd HH:mm:ss 格式化Calendar对象:
DateFormatUtils.format(Calendar.getInstance(),
"yyyy-MM-dd HH:mm:ss"): 2009-03-20 22:24:30
3: 以 yyyy-MM-dd HH:mm:ss 格式化TimeInMillis:
DateFormatUtils.format(Calendar.getInstance().getTimeInMillis(),
"yyyy-MM-dd HH:mm:ss"): 2009-03-20 22:24:30
http://blog.csdn.net/spring_0534/article/details/6256991
package com.kungeek.tip; import java.util.Date; import org.apache.commons.lang.time.DateFormatUtils; public class test { public static void main(String args[]){
Date date = new Date();
System.out.println(DateFormatUtils.ISO_DATE_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_DATETIME_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_TIME_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_TIME_NO_T_TIME_ZONE_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_TIME_TIME_ZONE_FORMAT.format(date));
System.out.println(DateFormatUtils.ISO_DATE_FORMAT.format(date) + " " + DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(date)); System.out.println("--------------------------------");
//----------------------------自定义模版
System.out.println(DateFormatUtils.format(date,"yyyyMMdd"));
System.out.println(DateFormatUtils.format(date,"yyyy-MM-dd-HH-mm-ss")); System.out.println(DateFormatUtils.format(date,"yyyyMMddhhmmss"));//12小时制
System.out.println(DateFormatUtils.format(date,"yyyyMMddHHmmss"));//24小时制 } }
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOgAAADgCAIAAACGmL1CAAAKBklEQVR4nO2dy7XquBZFSQsCIh0I4UVBq0KoDNyqToXwulTjAJaspZ/NPfbemnNU4yL02RILHWGtkk7P5/Off///+e/x199PyXQ7n07Xx/zi/e/HdU5/Pq4//wwz/OQ536b8v+fs4bvT7Xy+TVFaEEU1hjBxup1PUcXzixy1+qfbbTkai17PPK5hetC87tpP16/X8/u9XLawgSjx8zr52ILRU+nvSKNPZB6H222qfxxx2Xmg54LqU14kz8Sj+q7y9GwUblrZ6R3U68XppJX93CrcoIHz9RqNTymGn06+yt1uclC29DGoPlLAKW3oI9xXkTlE3bVEn7lsQSRx2jtlup1P12sSaDY9FW7YeCD6wscRffjzIMWt9Al35p1hpXChi3jG/U1yfwSyfxz2RAtXg3B/g2Si/TXMCPc1RAgXns+nIeH2khXu/wAODDMumAThgkkQLpgE4YJJ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bp10RAMxS6nNbYfz7j2PEbwzh6nNa48nnF5shxHaozMHqc1rjuesf88RnDMDqc1rjmecdV5jOCYPU5r7DieUbVebwj8s8dpjT3HM245jxEcs8tpjc3HM247jxEcs9NpjY3HM247jxEcw84ZmAThgkkQLpgE4YJJEC6YBOGCSca9hHqZJ3n0lt24TruzPtTsMEKZIS+hrubJb3zkXJq1jT7upP4yA15CXc9TKKu682i+jTrOw53UGxj3EupsnlJrzbdRt4RaHEYoM+4l1Lk8jQKKu/NZqrYsi7iT+gsMcgm1/g1UdvgUCkY59W3UDaEy425g3EuodZ4O+Twab6POhtq7HIKAcS+hlnlqpZpvo24KlTup1zPuJdQqT/WhVKY7QXL+T0PfMEIZds7AJAgXTIJwwSQIF0yCcMEkCBdM4um0RlGnbL3DmogX8ai4Oa1RhyT33JqtiXgRj4uX0xozFsFm4VatiXgRj4WX0xp1SNKFuMqaiBfxYDg5rbHqdJGmylZrIl7E4+HltMb6RFhdAKTWxO6+w6/h5bTGld7IijURL+JhcXNao6xTt95qTcSLeGAcndYo6pStN1sT8SIeGHbOwCQIF0yCcMEkCBdMgnDBJAgXTOLJ1pgkJs+zFmd1VB/HYWs8LG5sjR0HMGJrdIAXW2PPAYzYGh3gxdZYTEzVJtcu2BoN4cTWuCIxDGluVW7kYms8Hl5sjaXEgrqwNVrFi62xkFgSF7ZGq7ixNWYTkxRsjR5wZGvUiemkia3RA+ycgUkQLpgE4YJJEC6YBOGCSRAumAThgkkQLpgE4YJJEC6Y5D998E86bAkcgwAAAABJRU5ErkJggg==" alt="" />
4.1.6 RandomUtils
随机数据生成类,包括浮点,双精,布尔,整形,长整在内的随机数生成
RandomUtils.nextInt();采用默认的JVMRandom类,数值范围0~2147483647
nextInt(Random random);也可以设置其他的random
还支持以下方法:
nextLong();
nextBoolean();
nextFloat();
nextDouble();
RandomUtils.nextBoolean();
RandomUtils.nextDouble();
RandomUtils.nextLong();
// 注意这里传入的参数不是随机种子,而是在0~1000之间产生一位随机数
RandomUtils.nextInt(1000);
4.1.7 NumberUtils
为JDK中的Number类提供额外的功能。
提供可复用的值为0,1的数值型的包装类。包括Long、Integer、Short、Byte、Double、Float。
/*1.NumberUtils.isNumber():判断字符串是否是数字*/
NumberUtils.isNumber("5.96");//结果是true
NumberUtils.isNumber("s5");//结果是false
NumberUtils.isNumber("0000000000596");//结果是true
/*2.NumberUtils.isDigits():判断字符串中是否全为数字*/
NumberUtils.isDigits("0000000000.596");//false
NumberUtils.isDigits("0000000000596");//true
/*3.NumberUtils.toInt():字符串转换为整数*/
NumberUtils.toInt("5");
NumberUtils.toLong("5");
NumberUtils.toByte("3");
NumberUtils.toFloat("3.2");
NumberUtils.toDouble("4");
NumberUtils.toShort("3");
/*4.NumberUtils.max():找出最大的一个*/
NumberUtils.max(newint[]{3,5,6});//结果是6
NumberUtils.max(3,1,7);//结果是7
/*5.NumberUtils.min():找出最小的一个*/
NumberUtils.min(newint[]{3,5,6});//结果是6
NumberUtils.min(3,1,7);//结果是7
/*6.NumberUtils.createBigDecimal()通过字符串创建BigDecimal类型,支持long、int、float、double、number等数值*/
NumberUtils.createBigDecimal("1");
NumberUtils.createLong("1");
NumberUtils.createInteger("1");
http://www.cnblogs.com/linjiqin/archive/2013/11/14/3423856.html
4.1.8 FieldUtils
通过反射技术来操作成员变量。
1 getField族
Field getField(Class<?> ,String [,Boolean]);
Field getDeclaredField(Class<?>,String [,Boolean]);
说明:
getField: Gets an accessible Field
by name breaking scope if requested. 当前类的接口和和父类都会被考虑。
getDeclaredField : an accessible Field
by name respecting scope.
仅当前类被考虑。
http://jw-long.iteye.com/blog/1838178
http://www.yiibai.com/javalang/class_getfield.html
2 readField族
readStaticField(Field[,boolean]);
readStaticField(Class<?>,String[,boolean]);
readDeclaredStaticField(Class<?>,String[,boolean]);
readField(Field,Object[,boolean]);
readField(Object,String[,boolean]);
readDeclaredField(Object,String[,boolean])
获取字段的值。区别是:带有Declared的仅考虑当前类,其他情况会考虑当前类实现的接口以及其父类。
3 writeField族
writeStaticField(Field,Object[,boolean]);
writeStaticField(Class<?>,String,Object[,boolean]);
writeDeclaredStaticField(Class<?>,String,Object[,boolean]);
writeField(Field,Object,Object[,boolean]);
writeField(Object, String, Object[,boolean]);
writeDeclaredField(Object, String, Object[,boolean]);
设置字段的值.
4.1.8 CharUtils
静态类,不需要创建
1 public static boolean isAscii(char ch)
用途:判断是否为ascii字符
实现:
public static Boolean isAscii(char ch){
return ch < 128;
}
2 public static boolean isAsciiAlpha(char ch)
用途:判断是否为ascii字母,即值在65到90或者97到122
实现:
public static Boolean isAsciiAlpha(char ch) {
return (ch >= ‘A’&& ch <= ‘Z’) || (ch >= ‘a’&& CH <= ‘z’)
}
3 public static Boolean isAsciiAlphaLower(char ch)
同2. 判断范围是 65 到 90,即a 到 z.
4 public static boolean isAsciiAlphaUpper(char ch);
同2.判断范围是97到122.即A 到Z.
5 public static boolean isAsciiAlphanumeric(char ch)
用途:判断是否为ascii字符数字,即值在48到57,65到90或者97到122.
实现:
Public static boolean isAsciiAlphanumeric(char ch) {
return (ch >= ‘A’&& cn <= ‘Z’) || (ch >= ‘a’&& ch <= ‘z’) || (ch >= ‘0’&& ch <= ‘9’)
}
6 public static Boolean isAsciiControl(char ch)
用途:判断是否为控制字符
实现:
public static boolean isAsciiControl(char ch) {
return ch < 32 || ch = 127;
}
7 public static boolean isAsciiNumeric(char ch)
用途:判断是否为数字
实现:
Public static Boolean isAsciiNumeric(char ch) {
Return ch >= ‘0’ && ch <= ‘9’;
}
8 public static Boolean isAsciiPrintable(char ch)
用途:判断是否可打印出得ascii字符
实现:
Public static Boolean isAsciiPrintable(char ch) {
return ch >= 32 && ch < 127;
}
9 public static int toIntValue(char ch)
用途:数字转换
实现:
Public static int toIntValue(char ch) {
if(isAsciiNumeric(ch) == false) {
throw new IllegalArgumentException(“the character” + ch + “is not in the range ‘0’- ‘9’”)
}
Return ch – 48;
}
10 public static String unicodeEscaped(char ch)
用途:将ch转换为unicode表示的字符串形式
实现:
public static String unicodeEscaped(char ch) {
if(ch < 0x10) {
return “\\u000” + Integer.toHexString(ch);
}else if(ch < 0x100){
retrun “\\u00” + Integer.toHexString(ch);
}else if(ch < 0x1000) {
Return “\\u0” + Integer.toHexString(ch);
}
Return “\\u” + Integer.toHexString(ch);
}
4.1.10 BooleanUtils
1 negate(Boolean bool)
用法:否定指定的boolean值
2 isTrue(Boolean bool)
用法:检查一个boolean值是否为true,如果参数为null,返回false
3 isNotTrue(Boolean bool)
用法:检查一个boolean值是否为false,如果参数为null,返回true
4 isFalse(Boolean bool)
用法:检查一个boolean值是否为false,如果是 返回true.
如果检查的值为true或null返回false.
5 isNotFalse(Boolean bool)
用法:检查一个boolean值是否不为false,如果是返回true
6 toBoolean(Boolean bool)
用法:转换一个为null的boolean值,返回一个false.
* <pre>
* BooleanUtils.toBoolean(Boolean.TRUE) = true
* BooleanUtils.toBoolean(Boolean.FALSE) = false
* BooleanUtils.toBoolean(null) = false
* </pre>
7 toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)
用法: 转换一个为null的boolean值,返回后面参数给定的boolean值.
* <pre>
* BooleanUtils.toBooleanDefaultIfNull(Boolean.TRUE, false) = true
* BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false
* BooleanUtils.toBooleanDefaultIfNull(null, true) = true
* </pre>
*/
8 toBoolean(int value)
用法: 当参数为0是返回false,其它都返回true.
* <pre>
* BooleanUtils.toBoolean(0) = false
* BooleanUtils.toBoolean(1) = true
* BooleanUtils.toBoolean(2) = true
* </pre>
9 toBooleanObject(int value)
用法: 当参数为0是返回Boolean.FALSE对象,其它都返回Boolean.TRUE.
* <pre>
* BooleanUtils.toBoolean(0) = Boolean.FALSE
* BooleanUtils.toBoolean(1) = Boolean.TRUE
* BooleanUtils.toBoolean(2) = Boolean.TRUE
* </pre>
10 toBooleanObject(Integer value)
用法: 当参数为0是返回Boolean.FALSE对象,为null返回null
* 其它则返回Boolean.TRUE.
* <pre>
* BooleanUtils.toBoolean(new Integer(0)) = Boolean.FALSE
* BooleanUtils.toBoolean(new Integer(1)) = Boolean.TRUE
* BooleanUtils.toBoolean(new Integer(null)) = null
* </pre>
11 toBoolean(int value, int trueValue, int falseValue)
用法: * 如果第一个参数和第二个参数相等返回true,
* 如果第一个参数和第三个参数相等返回false,
* 如果都没有相等的,返回一个IllegalArgumentException
* * <pre>
* BooleanUtils.toBoolean(0, 1, 0) = false
* BooleanUtils.toBoolean(1, 1, 0) = true
* BooleanUtils.toBoolean(2, 1, 2) = false
* BooleanUtils.toBoolean(2, 2, 0) = true
* </pre>
4.1.11 ExceptionUtils
对异常的常见操作,获得堆栈,异常抛出方法名,错误链中对象数
public static Throwable getCause(Throwable [,String[]]);
用法:获取导致Throwable的Throwable. 可以设置自己制定的方法名称.
public static Throwable getRootCause(Throwable throwable);
用法:获取导致Throwable的 Root Throwable。
public static int getThrowableCount(Throwable throwable)
用法:统计异常链上的Throwable对象数量。
A throwable without cause will return 1;
A throwable with one cause will return 2 and so on
A null throwable will return 0.
Commons-lang API介绍的更多相关文章
- apache commons lang架包介绍
commons lang组件介绍和学习 介绍 Java语言开发时有一个隐患,那就是java支持null值,这就导致很多时候操作可能会出异常. 因此很多第三方组件都会提供安全null safe 操作(即 ...
- 让时间处理简单化 【第三方扩展类库org.apache.commons.lang.time】
JAVA的时间日期处理一直是一个比较复杂的问题,大多数程序员都不能很轻松的来处理这些问题.首先Java中关于时间的类,从 JDK 1.1 开始,Date的作用很有限,相应的功能已由Calendar与D ...
- Apache Commons 工具类介绍及简单使用
转自:http://www.cnblogs.com/younggun/p/3247261.html Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下 ...
- Apache Commons 工具集介绍
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下面是我这几年做开发过程中自己用过的工具类做简单介绍. 组件 功能介绍 BeanUtils 提供了对于 ...
- Apache Commons 工具类介绍及简单使用(转载)
原文链接 http://www.cnblogs.com/younggun/p/3247261.html Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动 ...
- Apache Commons Lang » 3.10使用简介
============================================================= 行文介绍: 1.诞生背景 2.引入方案 3.简单介绍 4 .详情介绍 文档: ...
- Java:Apache Commons 工具类介绍及简单使用
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下面是我这几年做开发过程中自己用过的工具类做简单介绍. Commons简介 组件 功能介绍 commo ...
- Apache Commons Lang
http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/package- ...
- Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解
Servlet基础(一) Servlet基础和关键的API介绍 Servlet简介 Java Servlet是和平台无关的服务器端组件,它运行在Servlet容器中. Servlet容器负责Servl ...
随机推荐
- 手机交互应用服务(状态栏提示信息Notifications)
官方的一个简单的例子: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon ...
- shiro基础学习(二)—shiro认证
一.shiro简介 shiro是apache旗下一个开源框架,它将软件系统的安全认证相关的功能抽取出来,实现用户身份认证.权限授权.加密.会话管理等功能,组成了一个通用的安全认证框架. 以下 ...
- DAM的使用结合串口和中断以及GPIO。
DAM的使用结合串口和中断以及GPIO. 当我学到DMA这章的时候就意味着我已经学完了,GPIO里的LED,按键,还有就是串口发送数据. 那么下面就来总结下前段时间所学的知识(因为接下来有断时间我是没 ...
- 事件驱动的Python实现
EventManager事件管理类实现,大概就百来行代码左右.如果有不了事件驱动的工作原理的可以看前一篇<事件驱动的简明讲解> # encoding: UTF-8 # 系统模块 from ...
- IOS 程序运行过程
第一次写有点小紧张 希望大家多多指教! 主要讲讲程序从点击运行到结束这个过程中后面的代码都有哪些变化. 首先先了解一下UIApplication.UIApplication的核心作用是提供IOS运行 ...
- 【理论篇】Percona XtraBackup 恢复单表
小明在某次操作中,误操作导致误删除了某个表,需要立即进行数据恢复. 如果是数据量较小的实例,并且有备份,即便是全备,做一次全量恢复,然后单表导出导入,虽然麻烦一点,却也花不了多少时间:如果是数据量大的 ...
- Eclipse显示内存占用
- ionic创建项目遇到的各种问题
前提:执行创建语句的前提是ionic环境已经装好,开始执行ionic start myApp blank. 提示已经有同名项目,是否覆盖.这里创建的是一个blank(空) 的ionic项目.还要两种是 ...
- DDD理论学习系列(1)-- 通用语言
1.引言 在开始之前,我想我们有必要先了解以下DDD的主要参与者.因为毕竟语言是人说的吗,就像我们面向对象编程一样,那通用语言面向的是? DDD的主要参与者:领域专家+开发人员 领域专家:精通业务的任 ...
- Linux之定时任务
定时任务Crond介绍 Crond是linux系统中用来定期执行命令/脚本或指定程序任务的一种服务或软件,一般情况下,我们安装完Centos5/6 linux操作系统之后,默认便会启动Crond任务调 ...