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 – 用于处理单词大小写、换行等。
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.fileupload.util.Closeable;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharSetUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.lang3.time.StopWatch;
public class TestStr {
public static void Commons(){
//null 和 ""操作~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//判断是否Null 或者 ""
System.out.println(StringUtils.isEmpty(null));
//System.out.println(StringUtils.isNotEmpty(null));
//判断是否null 或者 "" 去空格~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.out.println(StringUtils.isBlank(" "));
System.out.println(StringUtils.isNotBlank(null));
//去空格.Null返回null~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
System.out.println(StringUtils.trim(null));
//去空格,将Null和"" 转换为Null
System.out.println(StringUtils.trimToNull(""));
//去空格,将NULL 和 "" 转换为""
System.out.println(StringUtils.trimToEmpty(null));
//可能是对特殊空格符号去除??
System.out.println(StringUtils.strip("大家好 啊 \t"));
//同上,将""和null转换为Null
System.out.println(StringUtils.stripToNull(" \t"));
//同上,将""和null转换为""
System.out.println(StringUtils.stripToEmpty(null));
//将""或者Null 转换为 ""
System.out.println(StringUtils.defaultString(null));
//仅当字符串为Null时 转换为指定的字符串(二参数)
System.out.println(StringUtils.defaultString("", "df"));
//当字符串为null或者""时,转换为指定的字符串(二参数)
System.out.println(StringUtils.defaultIfEmpty(null, "sos"));
//去空格.去字符~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//如果第二个参数为null去空格(否则去掉字符串2边一样的字符,到不一样为止)
System.out.println(StringUtils.strip("fsfsdf", "f"));
//如果第二个参数为null只去前面空格(否则去掉字符串前面一样的字符,到不一样为止)
System.out.println(StringUtils.stripStart("ddsuuu ", "d"));
//如果第二个参数为null只去后面空格,(否则去掉字符串后面一样的字符,到不一样为止)
System.out.println(StringUtils.stripEnd("dabads", "das"));
//对数组没个字符串进行去空格。
ArrayToList(StringUtils.stripAll(new String[]{" 中华 ", "民 国 ", "共和 "}));
//如果第二个参数为null.对数组每个字符串进行去空格。(否则去掉数组每个元素开始和结尾一样的字符)
ArrayToList(StringUtils.stripAll(new String[]{" 中华 ", "民 国", "国共和国"}, "国"));
//查找,判断~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//判断2个字符串是否相等相等,Null也相等
System.out.println(StringUtils.equals(null, null));
//不区分大小写比较
System.out.println(StringUtils.equalsIgnoreCase("abc", "ABc"));
//查找,不知道怎么弄这么多查找,很多不知道区别在哪?费劲~~~~~~~~~~~~~~~~~~~
//普通查找字符,如果一参数为null或者""返回-1
System.out.println(StringUtils.indexOf(null, "a"));
//从指定位置(三参数)开始查找,本例从第2个字符开始查找k字符
System.out.println(