ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:20.04KB ,
资源ID:5979996      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5979996.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(阿帕奇常用函数总结.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

阿帕奇常用函数总结.docx

1、阿帕奇常用函数总结4.1 Commons-lang API介绍4.1.1 StringUtils4.1.2 StringEscapeUtils4.1.3 ArrayUtils4.1.4 DateUtils4.1.5 DateFormatUtils4.1.6 RandomUtils4.1.7 NumberUtils4.1.8 FieldUtils4.1.9 CharUtils4.1.10 BooleanUtils 4.1.11 ExceptionUtils1 StringUtils方法介绍StringUtils是提供字符串操作的工具类。提供的方法如下:1 public static boolea

2、n isEmpty(String str);说明:如果参数str为NULL或者str.length() = 0 返回true 对比:JDK 中类String的方法public boolean isEmpty()此方法通过判断私有变量count是否等于0来进行判断。2 public static boolean isNotEmpty(String str)说明:判断给定参数是否不为空,其实现方式利用了方法一: !isEmpty(str);对比:JDK中String类无此方法。3 public static boolean isBlank(String str);说明:如果参数str为NULL或者

3、其长度等于0,又或者其由空格组成,那么此方法都返回true。对比:JDK中String类无此方法。4 public static boolean isNotBlank(String str);说明:利用方法三实现。5 public static String trim(String str);说明:去除字符串开头和结尾处的空格字符。如果参数str为null,则返回null.对比:利用JDK中String类的trim()方法。6 public static String stripStart(String str, String stripChars);说明:去掉str前端的在stripChar

4、s中的字符7 public static String stripEnd(String str, String stripChars);说明:去掉str末端的在stripChars中的字符8 public static int ordinalIndexOf(String str, String searchStr, int ordinal)说明:返回字符串search在字符串str中第ordinal次出现的位置。如果str=null或searchStr=null或ordinalj时停止。11. 下标查找族11.1 indexOfObject,object,startIndex:Object为空

5、,则返回-1,。如果startIndex小于0,则置为0.如果object为空,则从数组的第一个位置开始找第一个为空的数据。否则,利用Object.equals()方法正向遍历数组,获取匹配的下标并返回。否则返回-1.4.1.4 DateUtils1 static finalMILLIS_PER_SECOND = 1000;一秒等于1000毫秒MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND; 一分钟等于多少毫秒MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;一小时等于多少毫秒MILLIS_PER_DAY = 24 * MI

6、LLIS_PER_HOUR;一天等于多少毫秒2 日期比较public static boolean isSameDay(Date date1, Date date2);public static boolean isSameDay(Calendar cal1, Calendar cal2);比较日期是否相同,忽略time具体是通过比较Calendar.ERA、YEAR、DAY_OF_YEAR三个属性判断给定日期是否相同.3 时间比较public static boolean isSameInstant(Date date1, Date date2);public static boolean

7、isSameInstant(Calendar cal1, Calendar cal2);比较时间是否相同.具体是通过Date类中的getTime()方法的。4 ADD族public static Date addYears(Date date, int amount);在给定日期date的基础上添加amount年,注意,函数返回新的对象;以下同上。addMonths();/月addWeeks();/周addDays();/日addHours();/小时addMinutes();/分钟addSeconds();/秒addMilliseconds();/毫秒5 set族public static

8、Date setYears(Date date, int amount);为date设置新的年份信息,并返回一个新的对象,对象date未发生改变.以下方法同上。setMonths();/设置月份setDays();/设置日期setHours();/设置小时setMinutes();/设置分钟setSeconds();/设置秒setMilliseconds();/设置毫秒6 round族、truncate族、ceil族日期取整(日期精度调节,如调节至秒/分等)Date round(Date date, int field);DateUtils.round()相当于数学中的四舍五入法取整Date

9、truncate(Date date, int field);DateUtils.truncate()相当与去余法取整。Date ceiling(Date date, int field);DateUtils.ceiling()相当于向上取整。能对Calendar类中几乎所有的field做日期取整,包括Calender.YEAR,Calendar.SECOND,Calendar.MINUTE,Calendar.HOUR,Calendar.DAY_OF_MONTH,Calendar.MONTH.4.1.5 DateFormatUtils 与SUN的SimpleDateFormat相比,其主要优点

10、是:线程安全。 对应于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

11、format (java.util.Date date)4.1.6 RandomUtils 随机数据生成类,包括浮点,双精,布尔,整形,长整在内的随机数生成RandomUtils.nextInt();采用默认的JVMRandom类,数值范围02147483647nextInt(Random random);也可以设置其他的random还支持以下方法:nextLong();nextBoolean();nextFloat();nextDouble();4.1.7 NumberUtils为JDK中的Number类提供额外的功能。提供可复用的值为0,1的数值型的包装类。包括Long、Integer、S

12、hort、Byte、Double、Float。toXXX(String str,XXX)族 将给定的字符串装换成XXX代表的数值类型,包括LongIntegerShortByteDoubleFloat。 如果指定了默认值XXX,那么当String为空,或是转换发生异常,则返回指定的默认值XXX。 createXXX(String)族用给定的字符串创建XXX数值类型的对象。包括FloatDoubleIntegerLongBigIntegerBigDecimal XXX min(XXX) 族从类型为XXX的数组中找出最小的。XXX可为longfloatdoublebyteshortint 时间复杂

13、度是O(n). XXX max(XXX) 族 同min族。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 respect

14、ing scope. 仅当前类被考虑。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的仅考虑当前类,其他情况会考虑当前类实现的接口

15、以及其父类。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

16、.1.8 CharUtils静态类,不需要创建1 public static boolean isAscii(char ch)用途:判断是否为ascii字符实现:public static Boolean isAscii(char ch) return ch = A& ch = a& CH = A& cn = a& ch = 0& ch = 9)6 public static Boolean isAsciiControl(char ch)用途:判断是否为控制字符实现:public static boolean isAsciiControl(char ch) return ch = 0 & ch

17、 = 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表示的字符串

18、形式实现: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)用法

19、:否定指定的boolean值2 isTrue(Boolean bool)用法:检查一个boolean值是否为true,如果参数为null,返回false3 isNotTrue(Boolean bool)用法:检查一个boolean值是否为false,如果参数为null,返回true4 isFalse(Boolean bool)用法:检查一个boolean值是否为false,如果是 返回true. 如果检查的值为true或null返回false.5 isNotFalse(Boolean bool)用法:检查一个boolean值是否不为false,如果是返回true6 toBoolean(Bool

20、ean bool)用法:转换一个为null的boolean值,返回一个false. * * BooleanUtils.toBoolean(Boolean.TRUE) = true * BooleanUtils.toBoolean(Boolean.FALSE) = false * BooleanUtils.toBoolean(null) = false * 7 toBooleanDefaultIfNull(Boolean bool, boolean valueIfNull)用法: 转换一个为null的boolean值,返回后面参数给定的boolean值. * * BooleanUtils.toB

21、ooleanDefaultIfNull(Boolean.TRUE, false) = true * BooleanUtils.toBooleanDefaultIfNull(Boolean.FALSE, true) = false * BooleanUtils.toBooleanDefaultIfNull(null, true) = true * */8 toBoolean(int value)用法: 当参数为0是返回false,其它都返回true. * * BooleanUtils.toBoolean(0) = false * BooleanUtils.toBoolean(1) = true

22、* BooleanUtils.toBoolean(2) = true * 9 toBooleanObject(int value)用法: 当参数为0是返回Boolean.FALSE对象,其它都返回Boolean.TRUE. * * BooleanUtils.toBoolean(0) = Boolean.FALSE * BooleanUtils.toBoolean(1) = Boolean.TRUE * BooleanUtils.toBoolean(2) = Boolean.TRUE * 10 toBooleanObject(Integer value)用法: 当参数为0是返回Boolean.F

23、ALSE对象,为null返回null * 其它则返回Boolean.TRUE. * * BooleanUtils.toBoolean(new Integer(0) = Boolean.FALSE * BooleanUtils.toBoolean(new Integer(1) = Boolean.TRUE * BooleanUtils.toBoolean(new Integer(null) = null * 11 toBoolean(int value, int trueValue, int falseValue)用法: * 如果第一个参数和第二个参数相等返回true, * 如果第一个参数和第三个参数相等返回false, * 如果都没有相等的,返回一个IllegalArgumentException * * * BooleanUtils.toBoolean(0, 1, 0) = false * BooleanUtils.toBoolean(1, 1, 0) = true * BooleanUtils.toBoolean(2, 1, 2) = false * BooleanUtils.toBoolean(2, 2, 0) = true * /pr

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1