Apache -Common-lang包使用

Apache Commons Lang 是一个提供了一系列实用工具类的Java库,包括ArrayUtils、BooleanUtils、CharEncoding、StringUtils等多个工具类,涵盖了数组操作、布尔值处理、字符编码判断、字符串处理等多种功能,为Java开发带来便利。
摘要由CSDN通过智能技术生成

此文出处:http://weigang-gao.iteye.com/blog/2188739

 

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(
commons-lang3.3.1.jar、Apache Commons中的一个,含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar。为JRE5.0+的更好的版本所提供 Jar文件含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE.txtMETA-INF/NOTICE.txtorg.apache.commons.lang.ArrayUtils.class org.apache.commons.lang.BitField.class org.apache.commons.lang.BooleanUtils.class org.apache.commons.lang.CharEncoding.class org.apache.commons.lang.CharRange.class org.apache.commons.lang.CharSet.class org.apache.commons.lang.CharSetUtils.class org.apache.commons.lang.CharUtils.class org.apache.commons.lang.ClassUtils.class org.apache.commons.lang.Entities$ArrayEntityMap.class org.apache.commons.lang.Entities$BinaryEntityMap.class org.apache.commons.lang.Entities$EntityMap.class org.apache.commons.lang.Entities$HashEntityMap.class org.apache.commons.lang.Entities$LookupEntityMap.class org.apache.commons.lang.Entities$MapIntMap.class org.apache.commons.lang.Entities$PrimitiveEntityMap.class org.apache.commons.lang.Entities$TreeEntityMap.class org.apache.commons.lang.Entities.class org.apache.commons.lang.IllegalClassException.class org.apache.commons.lang.IncompleteArgumentException.class org.apache.commons.lang.IntHashMap$Entry.class org.apache.commons.lang.IntHashMap.class org.apache.commons.lang.LocaleUtils.class org.apache.commons.lang.NotImplementedException.class org.apache.commons.lang.NullArgumentException.class org.apache.commons.lang.NumberRange.class org.apache.commons.lang.NumberUtils.class org.apache.commons.lang.ObjectUtils$Null.class org.apache.commons.lang.ObjectUtils.class org.apache.commons.lang.RandomStringUtils.class org.apache.commons.lang.SerializationException.class org.apache.commons.lang.SerializationUtils.class org.apache.commons.lang.StringEscapeUtils.class org.apache.commons.lang.StringUtils.class org.apache.commons.lang.SystemUtils.class org.apache.commons.lang.UnhandledException.class org.apache.commons.lang.Validate.class org.apache.commons.lang.WordUtils.class org.apache.commons.lang.builder.CompareToBuilder.class org.apache.commons.lang.builder.EqualsBuilder.class org.apache.commons.lang.builder.HashCodeBuilder.class org.apache.commons.lang.builder.ReflectionToStringBuilder$1.class org.apache.commons.lang.builder.ReflectionToStringBuilder.class org.apache.commons.lang.builder.StandardToStringStyle.class org.apache.commons.lang.builder.ToStringBuilder.class org.apache.commons.lang.builder.ToStringStyle$DefaultToStringStyle.class org.apache.commons.lang.builder.ToStringStyle$MultiLineToStringStyle.class org.apache.commons.lang.builder.ToStringStyle$NoFieldNameToStringStyle.class org.apache.commons.lang.builder.ToStringStyle$ShortPrefixToStringStyle.class org.apache.commons.lang.builder.ToStringStyle$SimpleToStringStyle.class org.apache.commons.lang.builder.ToStringStyle.class org.apache.commons.lang.enum.Enum$Entry.class org.apache.commons.lang.enum.Enum.class org.apache.commons.lang.enum.EnumUtils.class org.apache.commons.lang.enum.ValuedEnum.class org.apache.commons.lang.enums.Enum$Entry.class org.apache.commons.lang.enums.Enum.class org.apache.commons.lang.enums.EnumUtils.class org.apache.commons.lang.enums.ValuedEnum.class org.apache.commons.lang.exception.ExceptionUtils.class org.apache.commons.lang.exception.Nestable.class org.apache.commons.lang.exception.NestableDelegate.class org.apache.commons.lang.exception.NestableError.class org.apache.commons.lang.exception.NestableException.class org.apache.commons.lang.exception.NestableRuntimeException.class org.apache.commons.lang.math.DoubleRange.class org.apache.commons.lang.math.FloatRange.class org.apache.commons.lang.math.Fraction.class org.apache.commons.lang.math.IntRange.class org.apache.commons.lang.math.JVMRandom.class org.apache.commons.lang.math.LongRange.class org.apache.commons.lang.math.NumberRange.class org.apache.commons.lang.math.NumberUtils.class org.apache.commons.lang.math.RandomUtils.class org.apache.commons.lang.math.Range.class org.apache.commons.lang.mutable.Mutable.class org.apache.commons.lang.mutable.MutableBoolean.class org.apache.commons.lang.mutable.MutableByte.class org.apache.commons.lang.mutable.MutableDouble.class org.apache.commons.lang.mutable.MutableFloat.class org.apache.commons.lang.mutable.MutableInt.class org.apache.commons.lang.mutable.MutableLong.class org.apache.commons.lang.mutable.MutableObject.class org.apache.commons.lang.mutable.MutableShort.class org.apache.commons.lang.text.CompositeFormat.class org.apache.commons.lang.text.StrBuilder$StrBuilderReader.class org.apache.commons.lang.text.StrBuilder$StrBuilderTokenizer.class org.apache.commons.lang.text.StrBuilder$StrBuilderWriter.class org.apache.commons.lang.text.StrBuilder.class org.apache.commons.lang.text.StrLookup$MapStrLookup.class org.apache.commons.lang.text.StrLookup.class org.apache.commons.lang.text.StrMatcher$CharMatcher.class org.apache.commons.lang.text.StrMatcher$CharSetMatcher.class org.apache.commons.lang.text.StrMatcher$NoMatcher.class org.apache.commons.lang.text.StrMatcher$StringMatcher.class org.apache.commons.lang.text.StrMatcher$TrimMatcher.class org.apache.commons.lang.text.StrMatcher.class org.apache.commons.lang.text.StrSubstitutor.class org.apache.commons.lang.text.StrTokenizer.class org.apache.commons.lang.time.DateFormatUtils.class org.apache.commons.lang.time.DateUtils$DateIterator.class org.apache.commons.lang.time.DateUtils.class org.apache.commons.lang.time.DurationFormatUtils$Token.class org.apache.commons.lang.time.DurationFormatUtils.class org.apache.commons.lang.time.FastDateFormat$CharacterLiteral.class org.apache.commons.lang.time.FastDateFormat$NumberRule.class org.apache.commons.lang.time.FastDateFormat$PaddedNumberField.class org.apache.commons.lang.time.FastDateFormat$Pair.class org.apache.commons.lang.time.FastDateFormat$Rule.class org.apache.commons.lang.time.FastDateFormat$StringLiteral.class org.apache.commons.lang.time.FastDateFormat$TextField.class org.apache.commons.lang.time.FastDateFormat$TimeZoneDisplayKey.class org.apache.commons.lang.time.FastDateFormat$TimeZoneNameRule.class org.apache.commons.lang.time.FastDateFormat$TimeZoneNumberRule.class org.apache.commons.lang.time.FastDateFormat$TwelveHourField.class org.apache.commons.lang.time.FastDateFormat$TwentyFourHourField.class org.apache.commons.lang.time.FastDateFormat$TwoDigitMonthField.class org.apache.commons.lang.time.FastDateFormat$TwoDigitNumberField.class org.apache.commons.lang.time.FastDateFormat$TwoDigitYearField.class org.apache.commons.lang.time.FastDateFormat$UnpaddedMonthField.class org.apache.commons.lang.time.FastDateFormat$UnpaddedNumberField.class org.apache.commons.lang.time.FastDateFormat.class org.apache.commons.lang.time.StopWatch.class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值