apache commons-lang包

来源:互联网 发布:柠檬网络电视柠檬了tv 编辑:程序博客网 时间:2024/04/19 07:32
http://commons.apache.org/lang/api-release/overview-summary.html

这一组API的所有包名都以org.apache.commons.lang开头,共有如下8个包:

org.apache.commons.lang

org.apache.commons.lang.builder

org.apache.commons.lang.enum

org.apache.commons.lang.enums

org.apache.commons.lang.exception

org.apache.commons.lang.math

org.apache.commons.lang.mutable

org.apache.commons.lang.time

其中的lang.enum已不建议使用,替代它的是紧随其后的lang.enums包。 lang包主要是一些可以高度重用的Util类;lang.builder包包含了一组用于产生每个Java类中都常使用到的toString()、 hashCode()、equals()、compareTo()等等方法的构造器;lang.enums包顾名思义用于处理枚举;lang.exception包用于处理Java标准API中的exception,为1.4之前版本提供Nested Exception功能;lang.math包用于处理数字;lang.mutable用于包装值型变量;lang.time包提供处理日期和时间的功能。

我们首先来看org.apache.commons.lang包,这个包提供了一些有用的包含static方法的Util类。除了6个Exception类和2个已经deprecated的数字类之外,commons.lang包共包含了17个实用的类:

ArrayUtils – 用于对数组的操作,如添加、查找、删除、子数组、倒序、元素类型转换等;

BitField – 用于操作位元,提供了一些方便而安全的方法;

BooleanUtils – 用于操作和转换boolean或者Boolean及相应的数组;

CharEncoding – 包含了Java环境支持的字符编码,提供是否支持某种编码的判断;

CharRange – 用于设定字符范围并做相应检查;

CharSet – 用于设定一组字符作为范围并做相应检查;

CharSetUtils – 用于操作CharSet;

CharUtils – 用于操作char值和Character对象;

ClassUtils – 用于对Java类的操作,不使用反射;

ObjectUtils – 用于操作Java对象,提供null安全的访问和其他一些功能;

RandomStringUtils – 用于生成随机的字符串;

SerializationUtils – 用于处理对象序列化,提供比一般Java序列化更高级的处理能力;

StringEscapeUtils – 用于正确处理转义字符,产生正确的Java、JavaScript、HTML、XML和SQL代码;

StringUtils – 处理String的核心类,提供了相当多的功能;

SystemUtils – 在java.lang.System基础上提供更方便的访问,如用户路径、Java版本、时区、操作系统等判断;

Validate – 提供验证的操作,有点类似assert断言;

WordUtils – 用于处理单词大小写、换行等。

介绍下最常用的StringUtils类:

public class StringUtils extends Object

    * IsEmpty/IsBlank - checks if a String contains text
    * IsEmpty/IsBlank – 检查字符串是否有内容。
    * Trim/Strip - removes leading and trailing whitespace
    * Trim/Strip – 删除字符串开始和结尾的空白符。
    * Equals - compares two strings null-safe
    * Equals – 比较两个字符串null安全。
    * IndexOf/LastIndexOf/Contains - null-safe index-of checks
    * IndexOf/LastIndexOf/Contains – null安全的索引检查。
    * IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
    * IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut – 字符串集合索引检查。
    * ContainsOnly/ContainsNone - does String contains only/none of these characters
    * ContainsOnly/ContainsNone – 字符在字符串中出现一次或一次也没有出现。
    * Substring/Left/Right/Mid - null-safe substring extractions
    * Substring/Left/Right/Mid – null安全子串的提取。
    * SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
    * SubstringBefore/SubstringAfter/SubstringBetween – 子串提取依赖其它字符串。
    * Split/Join - splits a String into an array of substrings and vice versa
    * Split/Join – 字符串拆分为子串的字符串数组,反之亦然。
    * Remove/Delete - removes part of a String
    * Remove/Delete – 删除部分字符串。
    * Replace/Overlay - Searches a String and replaces one String with another
    * Replace/Overlay – 替换字符串的部分字符。
    * Chomp/Chop - removes the last part of a String
    * Chomp/Chop – 删除字符串最后的字符。
    * LeftPad/RightPad/Center/Repeat - pads a String
    * LeftPad/RightPad/Center/Repeat – 补字符串。
    * UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
    * UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize – 改变字符串的大小写。
    * CountMatches - counts the number of occurrences of one String in another
    * CountMatches – 计算一个字符或字符串在另外一个字符串出现的次数。
    * IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
    * IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable – 判断字符是否在字符串中。
    * DefaultString - protects against a null input String
    * DefaultString –null安全,null转换为字符串。
    * Reverse/ReverseDelimited - reverses a String
    * Reverse/ReverseDelimited – 反转字符串。
    * Abbreviate - abbreviates a string using ellipsis
    * Abbreviate – 缩写字符串用省略符。
    * Difference - compares two Strings and reports on their differences
    * Difference – 比较两个字符串并且返回不同。
    * LevensteinDistance - the number of changes needed to change one String into another
    * LevensteinDistance – 一个字符串改变为另一个字符串需要改变的数量。
0 0