StringUtils 源码,使用的是commons-lang3-3.1包。

StringUtils 源码,使用的是commons-lang3-3.1包。

下载地址 http://commons.apache.org/lang/download_lang.cgi


以下是StringUtils的各项用法
1.空字符串检查
使用函数: StringUtils.isBlank(testString)
函数介绍: 当testString为空,长度为零或者仅由空白字符(whitespace)组成时,返回True;否则返回False
例程:
    String test = "";
    String test2 = "\n\n\t";
    String test3 = null;
    String test4 = "Test";

    System.out.println( "test blank? " + StringUtils.isBlank( test ) );
    System.out.println( "test2 blank? " + StringUtils.isBlank( test2 ) );
    System.out.println( "test3 blank? " + StringUtils.isBlank( test3 ) );
    System.out.println( "test4 blank? " + StringUtils.isBlank( test4 ) );
输出如下:
test blank? true
test2 blank? true
test3 blank? true
test4 blank? False
函数StringUtils.isNotBlank(testString)的功能与StringUtils.isBlank(testString)相反.


2.清除空白字符
使用函数: StringUtils.trimToNull(testString)
函数介绍:清除掉testString首尾的空白字符,如果仅testString全由空白字符
(whitespace)组成则返回null
例程:
    String test1 = "\t";
    String test2 = "  A  Test  ";
    String test3 = null;

    System.out.println( "test1 trimToNull: " + StringUtils.trimToNull( test1 ) );
    System.out.println( "test2 trimToNull: " + StringUtils.trimToNull( test2 ) );
    System.out.println( "test3 trimToNull: " + StringUtils.trimToNull( test3 ) );

输出如下:
test1 trimToNull: null
test2 trimToNull: A  Test
test3 trimToNull: null

注意:函数StringUtils.trim(testString)与
StringUtils.trimToNull(testString)功能类似,但testString由空白字符
(whitespace)组成时返回零长度字符串。


3.取得字符串的缩写
使用函数: StringUtils.abbreviate(testString,width)和StringUtils.abbreviate(testString,offset,width)
函数介绍:在给定的width内取得testString的缩写,当testString的长度小于width则返回原字符串.
例程:
    String test = "This is a test of the abbreviation.";
    String test2 = "Test";

    System.out.println( StringUtils.abbreviate( test, 15 ) );
    System.out.println( StringUtils.abbreviate( test, 5,15 ) );
    System.out.println( StringUtils.abbreviate( test2, 10 ) );
输出如下:
This is a te...
...is a test...
Test

4.劈分字符串
使用函数: StringUtils.split(testString,splitChars,arrayLength)
函数介绍:splitChars中可以包含一系列的字符串来劈分testString,并可以设定得
到数组的长度.注意设定长度arrayLength和劈分字符串间有抵触关系,建议一般情况下
不要设定长度.
例程:
    String input = "A b,c.d|e";
    String input2 = "Pharmacy, basketball funky";

    String[] array1 = StringUtils.split( input, " ,.|");
    String[] array2 = StringUtils.split( input2, " ,", 2 );


    System.out.println( ArrayUtils.toString( array1 ) );
    System.out.println( ArrayUtils.toString( array2 ) );
输出如下:
{A,b,c,d,e}
{Pharmacy,basketball funky}

5.查找嵌套字符串
使用函数:StringUtils.substringBetween(testString,header,tail)
函数介绍:在testString中取得header和tail之间的字符串。不存在则返回空
例程:
    String htmlContent = "ABC1234ABC4567";
    System.out.println(StringUtils.substringBetween(htmlContent, "1234", "4567"));
    System.out.println(StringUtils.substringBetween(htmlContent, "12345", "4567"));
输出如下:
    ABC
    null


6.去除尾部换行符
使用函数:StringUtils.chomp(testString)
函数介绍:去除testString尾部的换行符
例程:
    String input = "Hello\n";
    System.out.println( StringUtils.chomp( input ));
    String input2 = "Another test\r\n";
    System.out.println( StringUtils.chomp( input2 ));
输出如下:
    Hello
    Another test


7.重复字符串
使用函数:StringUtils.repeat(repeatString,count)
函数介绍:得到将repeatString重复count次后的字符串
例程:
    System.out.println( StringUtils.repeat( "*", 10));
    System.out.println( StringUtils.repeat( "China ", 5));
输出如下:
    **********
    China China China China China

其他函数:StringUtils.center( testString, count,repeatString );
函数介绍:把testString插入将repeatString重复多次后的字符串中间,得到字符串
的总长为count
例程:
    System.out.println( StringUtils.center( "China", 11,"*"));
输出如下:
    ***China***


8.颠倒字符串
使用函数:StringUtils.reverse(testString)
函数介绍:得到testString中字符颠倒后的字符串
例程:
    System.out.println( StringUtils.reverse("ABCDE"));
输出如下:
    EDCBA

9.判断字符串内容的类型
函数介绍:
StringUtils.isNumeric( testString ) :如果testString全由数字组成返回True
StringUtils.isAlpha( testString ) :如果testString全由字母组成返回True
StringUtils.isAlphanumeric( testString ) :如果testString全由数字或数字组
成返回True
StringUtils.isAlphaspace( testString )  :如果testString全由字母或空格组
成返回True

例程:
    String state = "Virginia";
    System.out.println( "Is state number? " + StringUtils.isNumeric(
state ) );
    System.out.println( "Is state alpha? " + StringUtils.isAlpha( state )
);
    System.out.println( "Is state alphanumeric? " +StringUtils.isAlphanumeric( state ) );
    System.out.println( "Is state alphaspace? " + StringUtils.isAlphaSpace( state ) );
输出如下:
    Is state number? false
    Is state alpha? true
    Is state alphanumeric? true
    Is state alphaspace? true

10.取得某字符串在另一字符串中出现的次数
使用函数:StringUtils.countMatches(testString,seqString)
函数介绍:取得seqString在testString中出现的次数,未发现则返回零
例程:
    System.out.println(StringUtils.countMatches( "Chinese People", "e"
));
输出:
    4

11.部分截取字符串
使用函数:
StringUtils.substringBetween(testString,fromString,toString ):取得两字符
之间的字符串
StringUtils.substringAfter( ):取得指定字符串后的字符串
StringUtils.substringBefore( ):取得指定字符串之前的字符串
StringUtils.substringBeforeLast( ):取得最后一个指定字符串之前的字符串
StringUtils.substringAfterLast( ):取得最后一个指定字符串之后的字符串

函数介绍:上面应该都讲明白了吧。
例程:
    String formatted = " 25 * (30,40) [50,60] | 30";
    System.out.print("N0: " + StringUtils.substringBeforeLast( formatted, "*" ) );
    System.out.print(", N1: " + StringUtils.substringBetween( formatted, "(", "," ) );
    System.out.print(", N2: " + StringUtils.substringBetween( formatted, ",", ")" ) );
    System.out.print(", N3: " + StringUtils.substringBetween( formatted, "[", "," ) );
    System.out.print(", N4: " + StringUtils.substringBetween( formatted, ",", "]" ) );
    System.out.print(", N5: " + StringUtils.substringAfterLast( formatted, "|" ) );
输出如下:
    N0:  25 , N1: 30, N2: 40, N3: 50, N4: 40) [50,60, N5:  30

1. 检查字符串是否为空:

 

 static boolean isBlank(CharSequence str)  判断字符串是否为空或null;
 static boolean isNotBlank(CharSequence str) 判断字符串是否非空或非null;

 

 StringUtils.isBlank("a");
 返回结果为: false;

 

2. 缩进字符串:

 

 static String abbreviate(String str, int maxWidth) 缩进字符串,第二个参数至少为4(包括...)

 

 StringUtils.abbreviate("abcdefg", 20);
 返回结果为:abcdefg (正常显示)

 StringUtils.abbreviate("abcdefg", 4);
 返回结果为:a...

 

3. 首字母大写:

 

 static String capitalize(String str) 首字母大写
 static String uncapitalize(String str)首字母小写  

 

 StringUtils.capitalize("abcdefg");
 返回结果:Abcdefg

 

4. 字符串显示在一个大字符串的位置:

 

 static String center(String str, int size);  默认以空格填充
 static String center(String str, int size, String padString); 其余位置字符串填充
 public static String leftPad(String str,int size); 左侧空格填充
 public static String leftPad(String str,int size,String padStr);左侧字符串填充
 public static String rightPad(String str,int size); 左侧空格填充
 public static String rightPad(String str,int size,String padStr);左侧字符串填充
 

 StringUtils.center("abcdefg", 20);
 返回结果:      abcdefg      

 StringUtils.center("abcdefg", 20,"*_");
 返回结果:*_*_*_abcdefg*_*_*_*

 StringUtils.leftPad("abc", 10, "*");
 返回结果:*******abc

 

5. 重复字符串次数

 

 static String repeat(String str, int repeat);

 

 StringUtils.repeat("abc", 5); 
 返回结果:abcabcabcabcabc

 

6. 是否全是大写,是否全是小写(3.0版本)

 

 public static boolean isAllLowerCase(String str);
 public static boolean isAllUpperCase(String str);

 

 StringUtils.isAllLowerCase("abC");
 返回结果:false

 

7. 是否都是由字母组成:

 

 public static boolean isAlpha(String str);  只由字母组成
 public static boolean isAlphaSpace(String str); 只有字母和空格组成
 public static boolean isAlphanumeric(String str);只由字母和数字组成
 public static boolean isAlphanumericSpace(String str);只由字母数字和空格组成
 public static boolean isNumeric(String str);只由数字组成
 public static boolean isNumericSpace(String str);只由数字和空格组成

 

 StringUtils.isAlpha("a2bdefg");
 返回结果:false

 

8. 小字符串在大字符串中的匹配次数

 

public static int countMatches(String str,String sub);

 

StringUtils.countMatches("ababsssababa", "ab");
 返回结果:4

 

9. 字符串倒转

 

 public static String reverse(String str);

 

 StringUtils.reverse("abcdef");
 返回结果:fedcba

 

10. 大小写转换,空格不动
 

 public static String swapCase(String str);

 

 StringUtils.swapCase("I am a-A*a")
 返回结果:i AM A-a*A

一、数组转成字符串: 
1、 将数组中的字符转换为一个字符串 
将数组中的字符转换为一个字符串 

@param strToConv 要转换的字符串 ,默认以逗号分隔 
@return 返回一个字符串 
String[3] s={"a","b","c"} 
StringUtil.convString(s)="a,b,c" 
2、 static public String converString(String strToConv) 
@param strToConv 要转换的字符串 , 
@param conv 分隔符,默认以逗号分隔 
@return 同样返回一个字符串 

String[3] s={"a","b","c"} 
StringUtil.convString(s,"@")="a@b@c" 
static public String converString(String strToConv, String conv) 


二、空值检测: 
3、 

Checks if a String is empty ("") or null. 


判断一个字符串是否为空,空格作非空处理。 StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false 

NOTE: This method changed in Lang version 2.0. 

It no longer trims the String. 
That functionality is available in isBlank(). 


@param str the String to check, may be null 
@return true if the String is empty or null 
public static boolean isEmpty(String str) 


三、非空处理: 
4、 
Checks if a String is not empty ("") and not null. 


判断一个字符串是否非空,空格作非空处理. StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true 

@param str the String to check, may be null 
@return true if the String is not empty and not null 
public static boolean isNotEmpty(String str) 

5、 

Checks if a String is not empty (""), not null and not whitespace only. 


判断一个字符串是否非空,空格作空处理. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true 

@param str the String to check, may be null 
@return true if the String is 
not empty and not null and not whitespace 
@since 2.0 
public static boolean isNotBlank(String str) 


四、 空格处理 
6、 
Removes control characters (char <= 32) from both 

ends of this String, handling null by returning 
null. 


The String is trimmed using {@link String#trim()}. 

Trim removes start and end characters <= 32. 
To strip whitespace use {@link //strip(String)}. 


To trim your choice of characters, use the 

{@link //strip(String, String)} methods. 


格式化一个字符串中的空格,有非空判断处理; StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc" 

@param str the String to be trimmed, may be null 
@return the trimmed string, null if null String input 
public static String trim(String str) 

7、 


Removes control characters (char <= 32) from both 

ends of this String returning null if the String is 
empty ("") after the trim or if it is null. 

The String is trimmed using {@link String#trim()}. 

Trim removes start and end characters <= 32. 
To strip whitespace use {@link /stripToNull(String)}. 


格式化一个字符串中的空格,有非空判断处理,如果为空返回null; StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc" 

@param str the String to be trimmed, may be null 
@return the trimmed String, 
null if only chars <= 32, empty or null String input 
@since 2.0 
public static String trimToNull(String str) 

8、 


Removes control characters (char <= 32) from both 

ends of this String returning an empty String ("") if the String 
is empty ("") after the trim or if it is null. 

The String is trimmed using {@link String#trim()}. 

Trim removes start and end characters <= 32. 
To strip whitespace use {@link /stripToEmpty(String)}. 


格式化一个字符串中的空格,有非空判断处理,如果为空返回""; StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc" 

@param str the String to be trimmed, may be null 
@return the trimmed String, or an empty String if null input 
@since 2.0 
public static String trimToEmpty(String str) 


五、 字符串比较: 
9、 
Compares two Strings, returning true if they are equal. 


nulls are handled without exceptions. Two null 

references are considered to be equal. The comparison is case sensitive. 


判断两个字符串是否相等,有非空处理。 StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false 

@param str1 the first String, may be null 
@param str2 the second String, may be null 
@return true if the Strings are equal, case sensitive, or 
both null 
@see java.lang.String#equals(Object) 
public static boolean equals(String str1, String str2) 


10、 

Compares two Strings, returning true if they are equal ignoring 

the case. 


nulls are handled without exceptions. Two null 

references are considered equal. Comparison is case insensitive. 


判断两个字符串是否相等,有非空处理。忽略大小写 StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, "abc") = false StringUtils.equalsIgnoreCase("abc", null) = false StringUtils.equalsIgnoreCase("abc", "abc") = true StringUtils.equalsIgnoreCase("abc", "ABC") = true 

@param str1 the first String, may be null 
@param str2 the second String, may be null 
@return true if the Strings are equal, case insensitive, or 
both null 
@see java.lang.String#equalsIgnoreCase(String) 
public static boolean equalsIgnoreCase(String str1, String str2) 


六、 IndexOf 处理 
11、 


Finds the first index within a String, handling null. 

This method uses {@link String#indexOf(String)}. 


A null String will return -1. 


返回要查找的字符串所在位置,有非空处理 StringUtils.indexOf(null, *) = -1 StringUtils.indexOf(*, null) = -1 StringUtils.indexOf("", "") = 0 StringUtils.indexOf("aabaabaa", "a") = 0 StringUtils.indexOf("aabaabaa", "b") = 2 StringUtils.indexOf("aabaabaa", "ab") = 1 StringUtils.indexOf("aabaabaa", "") = 0 

@param str the String to check, may be null 
@param searchStr the String to find, may be null 
@return the first index of the search String, 
-1 if no match or null string input 
@since 2.0 
public static int indexOf(String str, String searchStr) 

12、 

Finds the first index within a String, handling null. 

This method uses {@link String#indexOf(String, int)}. 


A null String will return -1. 

A negative start position is treated as zero. 
An empty ("") search String always matches. 
A start position greater than the string length only matches 
an empty search String. 


返回要由指定位置开始查找的字符串所在位置,有非空处理 StringUtils.indexOf(null, *, *) = -1 StringUtils.indexOf(*, null, *) = -1 StringUtils.indexOf("", "", 0) = 0 StringUtils.indexOf("aabaabaa", "a", 0) = 0 StringUtils.indexOf("aabaabaa", "b", 0) = 2 StringUtils.indexOf("aabaabaa", "ab", 0) = 1 StringUtils.indexOf("aabaabaa", "b", 3) = 5 StringUtils.indexOf("aabaabaa", "b", 9) = -1 StringUtils.indexOf("aabaabaa", "b", -1) = 2 StringUtils.indexOf("aabaabaa", "", 2) = 2 StringUtils.indexOf("abc", "", 9) = 3 

@param str the String to check, may be null 
@param searchStr the String to find, may be null 
@param startPos the start position, negative treated as zero 
@return the first index of the search String, 
-1 if no match or null string input 
@since 2.0 
public static int indexOf(String str, String searchStr, int startPos) 


七、 子字符串处理: 
13、 
Gets a substring from the specified String avoiding exceptions. 


A negative start position can be used to start n 

characters from the end of the String. 


A null String will return null. 

An empty ("") String will return "". 


返回指定位置开始的字符串中的所有字符 StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc" 

@param str the String to get the substring from, may be null 
@param start the position to start from, negative means 
count back from the end of the String by this many characters 
@return substring from start position, null if null String input 
public static String substring(String str, int start) 

14、 

Gets a substring from the specified String avoiding exceptions. 


A negative start position can be used to start/end n 

characters from the end of the String. 


The returned substring starts with the character in the start 

position and ends before the end position. All postion counting is 
zero-based -- i.e., to start at the beginning of the string use 
start = 0. Negative start and end positions can be used to 
specify offsets relative to the end of the String. 


If start is not strictly to the left of end, "" 

is returned. 


返回由开始位置到结束位置之间的子字符串 StringUtils.substring(null, *, *) = null StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" StringUtils.substring("abc", -2, -1) = "b" StringUtils.substring("abc", -4, 2) = "ab" 

@param str the String to get the substring from, may be null 
@param start the position to start from, negative means 
count back from the end of the String by this many characters 
@param end the position to end at (exclusive), negative means 
count back from the end of the String by this many characters 
@return substring from start position to end positon, 
null if null String input 
public static String substring(String str, int start, int end) 


15、 SubStringAfter/SubStringBefore(前后子字符串处理: 


Gets the substring before the first occurance of a separator. 

The separator is not returned. 


A null string input will return null. 

An empty ("") string input will return the empty string. 
A null separator will return the input string. 


返回指定字符串之前的所有字符 StringUtils.substringBefore(null, *) = null StringUtils.substringBefore("", *) = "" StringUtils.substringBefore("abc", "a") = "" StringUtils.substringBefore("abcba", "b") = "a" StringUtils.substringBefore("abc", "c") = "ab" StringUtils.substringBefore("abc", "d") = "abc" StringUtils.substringBefore("abc", "") = "" StringUtils.substringBefore("abc", null) = "abc" 

@param str the String to get a substring from, may be null 
@param separator the String to search for, may be null 
@return the substring before the first occurance of the separator, 
null if null String input 
@since 2.0 
public static String substringBefore(String str, String separator) 

16、 

Gets the substring after the first occurance of a separator. 

The separator is not returned. 


A null string input will return null. 

An empty ("") string input will return the empty string. 
A null separator will return the empty string if the 
input string is not null. 


返回指定字符串之后的所有字符 StringUtils.substringAfter(null, *) = null StringUtils.substringAfter("", *) = "" StringUtils.substringAfter(*, null) = "" StringUtils.substringAfter("abc", "a") = "bc" StringUtils.substringAfter("abcba", "b") = "cba" StringUtils.substringAfter("abc", "c") = "" StringUtils.substringAfter("abc", "d") = "" StringUtils.substringAfter("abc", "") = "abc" 

@param str the String to get a substring from, may be null 
@param separator the String to search for, may be null 
@return the substring after the first occurance of the separator, 
null if null String input 
@since 2.0 
public static String substringAfter(String str, String separator) 

17、 

Gets the substring before the last occurance of a separator. 

The separator is not returned. 


A null string input will return null. 

An empty ("") string input will return the empty string. 
An empty or null separator will return the input string. 


返回最后一个指定字符串之前的所有字符 StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast("", *) = "" StringUtils.substringBeforeLast("abcba", "b") = "abc" StringUtils.substringBeforeLast("abc", "c") = "ab" StringUtils.substringBeforeLast("a", "a") = "" StringUtils.substringBeforeLast("a", "z") = "a" StringUtils.substringBeforeLast("a", null) = "a" StringUtils.substringBeforeLast("a", "") = "a" 

@param str the String to get a substring from, may be null 
@param separator the String to search for, may be null 
@return the substring before the last occurance of the separator, 
null if null String input 
@since 2.0 
public static String substringBeforeLast(String str, String separator) 

18、 

Gets the substring after the last occurance of a separator. 

The separator is not returned. 


A null string input will return null. 

An empty ("") string input will return the empty string. 
An empty or null separator will return the empty string if 
the input string is not null. 


返回最后一个指定字符串之后的所有字符 StringUtils.substringAfterLast(null, *) = null StringUtils.substringAfterLast("", *) = "" StringUtils.substringAfterLast(*, "") = "" StringUtils.substringAfterLast(*, null) = "" StringUtils.substringAfterLast("abc", "a") = "bc" StringUtils.substringAfterLast("abcba", "b") = "a" StringUtils.substringAfterLast("abc", "c") = "" StringUtils.substringAfterLast("a", "a") = "" StringUtils.substringAfterLast("a", "z") = "" 

@param str the String to get a substring from, may be null 
@param separator the String to search for, may be null 
@return the substring after the last occurance of the separator, 
null if null String input 
@since 2.0 
public static String substringAfterLast(String str, String separator) 


八、 Replacing(字符串替换) 
19、 
Replaces all occurances of a String within another String. 


A null reference passed to this method is a no-op. 


以指定字符串替换原来字符串的的指定字符串 StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "aba" StringUtils.replace("aba", "a", "z") = "zbz" 

@param text text to search and replace in, may be null 
@param repl the String to search for, may be null 
@param with the String to replace with, may be null 
@return the text with any replacements processed, 
null if null String input 
@see #replace(String text, String repl, String with, int max) 
public static String replace(String text, String repl, String with) 

20、 

Replaces a String with another String inside a larger String, 

for the first max values of the search String. 


A null reference passed to this method is a no-op. 


以指定字符串最大替换原来字符串的的指定字符串 StringUtils.replace(null, *, *, *) = null StringUtils.replace("", *, *, *) = "" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", "a", null, 1) = "abaa" StringUtils.replace("abaa", "a", "", 1) = "abaa" StringUtils.replace("abaa", "a", "z", 0) = "abaa" StringUtils.replace("abaa", "a", "z", 1) = "zbaa" StringUtils.replace("abaa", "a", "z", 2) = "zbza" StringUtils.replace("abaa", "a", "z", -1) = "zbzz" 

@param text text to search and replace in, may be null 
@param repl the String to search for, may be null 
@param with the String to replace with, may be null 
@param max maximum number of values to replace, or -1 if no maximum 
@return the text with any replacements processed, 
null if null String input 
public static String replace(String text, String repl, String with, int max) 


九、 Case conversion(大小写转换) 
21、 

Converts a String to upper case as per {@link String#toUpperCase()}. 


A null input String returns null. 


将一个字符串变为大写 StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC" 

@param str the String to upper case, may be null 
@return the upper cased String, null if null String input 
public static String upperCase(String str) 22、 

Converts a String to lower case as per {@link String#toLowerCase()}. 


A null input String returns null. 


将一个字符串转换为小写 StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc" 

@param str the String to lower case, may be null 
@return the lower cased String, null if null String input 
public static String lowerCase(String str) 23、 

Capitalizes a String changing the first letter to title case as 

per {@link Character#toTitleCase(char)}. No other letters are changed. 


For a word based alorithm, see {@link /WordUtils#capitalize(String)}. 

A null input String returns null. 


StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" 

@param str the String to capitalize, may be null 
@return the capitalized String, null if null String input 
@see /WordUtils#capitalize(String) 
@see /uncapitalize(String) 
@since 2.0 
将字符串中的首字母大写 
public static String capitalize(String str)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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
### 回答1: org.apache.commons commons-lang3-3.1是一个Apache软件基金会中的一个实用程序库。它含了大量的实用工具类和方法,使Java开发人员可以更快、更方便地编写Java代码。在这个库中,开发人员可以找到很多常用的功能,例如字符串操作、日期和时间处理、随机数生成、数组操作、文件操作、数学计算等等。通过这个库,我们可以快速地实现各种功能,提高我们的开发效率。 下载org.apache.commons commons-lang3-3.1非常简单。可以在Apache官网上进行下载,也可以在Maven中央仓库中下载。只需要将对应的jar加入到我们的工程中即可使用。通过使用Org.apache.commons commons-lang3-3.1这个工具集,我们可以在Java开发中更加得心应手,更加高效地完成开发任务,为我们的项目赢得更多的成功。 ### 回答2: org.apache.commons commons-lang3-3.1是一个Apache软件基金会提供的开Java类库,主要提供了一系列通用的工具类和方法,用于字符串处理、日期处理、基本类型转换等常用操作,简化了Java开发过程中的一些常见任务。 下载这个类库可以到Apache官网的下载页面进行下载,并且也可在Maven仓库中通过依赖的方式引入。使用时只需要将其添加到Java项目的classpath中即可。 这个版本的commons-lang3含了很多实用的工具类和方法,比如StringUtils类可以方便地处理字符串的格式化、剪切、替换、分割等操作;DateUtils类提供了对日期和时间的各种处理,括格式化、加减、比较等等;ArrayUtils类提供了对数组的各种操作,括复制、添加、查找等等。这些工具类的使用可以大大简化Java开发的工作量,提高代码的可读性和可维护性。 总的来说,org.apache.commons commons-lang3-3.1是一个非常实用的Java类库,推荐给Java开发者使用。 ### 回答3: org.apache.commons commons-lang3-3.1是一个基于Java语言编写的开软件库。它含了一系列通用的工具类、方法和实用函数,可以帮助开发者更加高效地完成各种Java应用程序的开发工作。 这个开软件库主要含了字符串处理、文件处理、日期时间处理、随机数生成、对象操作、反射等多个方面的功能模块。在实际开发中,我们可以直接引入这个软件库,并调用其中封装好的方法和函数,来完成一些常规性的编码任务。 org.apache.commons commons-lang3-3.1的下载方式是在Apache官网上进行下载。我们可以在官网上找到相应的下载链接,并选择适用于当前开发环境的版本进行下载。下载后,我们需要将其集成到当前的Java应用程序中,并在代码中引入相关的依赖库和,才能顺利使用其中的功能模块。 总之,org.apache.commons commons-lang3-3.1是一个常用的Java开软件库,封装了多种常用的工具类、方法和实用函数,可以大大简化Java程序的开发过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值