当前位置:网站首页>[Commons lang3 topic] 001 stringutils topic
[Commons lang3 topic] 001 stringutils topic
2022-07-29 00:58:00 【Zibo Zibo】
【commons-lang3 project 】001-StringUtils project
List of articles
- 【commons-lang3 project 】001-StringUtils project
- 〇、 Get ready
- One 、 Judgment is not empty
- 1、 Determines if the string is empty :null、""、" " by true , For the other false
- 2、 Determine if the string is not empty ( And isBlank contrary ):null、""、" " by false , For the other true
- 3、 Determines if the string is empty :null、"" by true , For the other false
- 4、 Determine if the string is not empty ( And isEmpty contrary ):null、"" by false , For the other true
- Two 、 Judgment type
- 5、 Determine whether the string is a number , Don't ignore spaces
- 6、 Determine whether the string is a number , Ignore spaces
- 7、 Determine whether the string is a Greek letter , Don't ignore spaces
- 8、 Determine whether the string is a Greek letter , Ignore spaces
- 9、 Judge whether the string is composed of Greek letters and numbers , Don't ignore spaces
- 10、 Judge whether the string is composed of Greek letters and numbers , Ignore spaces
- 3、 ... and 、 Determine case
- Four 、 Judgment includes
- 13、 Judge whether the source string contains the target string
- 14、 Determine whether the source string contains the destination byte
- 15、 Judge whether the source string contains the target string ( Multiple goals )
- 16、 Determine whether the source string contains the destination byte ( Multiple goals )
- 5、 ... and 、 Space before and after
- 6、 ... and 、 Determine whether two strings are equal
- 7、 ... and 、 Find the target string location
- 22、 Find the position where the target string first appears in the source string , No return -1
- 23、 Find the position where the target string first appears in the source string , No return -1( Start at the specified location )
- 24、 Find the index position of any element in the array in the source string , Meet multiple hours , Minimum value , No return -1( Multiple goals )
- 8、 ... and 、 toggle case
- Nine 、 Omission and supplement
- Ten 、 Compare strings
- 11、 ... and 、 Find the number of occurrences
- Twelve 、 The separator separates
- 13、 ... and 、 Null, default value
- fourteen 、 Complete code
〇、 Get ready
1、StringUtils The main role
Provide all kinds of String manipulation Method .
2、 Introduce dependencies
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
One 、 Judgment is not empty
1、 Determines if the string is empty :null、“”、" " by true , For the other false
// 1、 Determines if the string is empty :null、""、" " by true , For the other false
System.out.println(StringUtils.isBlank(null)); // true
System.out.println(StringUtils.isBlank("")); // true
System.out.println(StringUtils.isBlank(" ")); // true
System.out.println(StringUtils.isBlank(" zibo ")); // false
2、 Determine if the string is not empty ( And isBlank contrary ):null、“”、" " by false , For the other true
// 2、 Determine if the string is not empty ( And isBlank contrary ):null、""、" " by false , For the other true
System.out.println(StringUtils.isNotBlank(null)); // true
System.out.println(StringUtils.isNotBlank("")); // true
System.out.println(StringUtils.isNotBlank(" ")); // true
System.out.println(StringUtils.isNotBlank(" zibo ")); // true
3、 Determines if the string is empty :null、“” by true , For the other false
// 3、 Determines if the string is empty :null、"" by true , For the other false
System.out.println(StringUtils.isEmpty(null)); // true
System.out.println(StringUtils.isEmpty("")); // true
System.out.println(StringUtils.isEmpty(" ")); // false
System.out.println(StringUtils.isEmpty(" zibo ")); // false
4、 Determine if the string is not empty ( And isEmpty contrary ):null、“” by false , For the other true
// 4、 Determine if the string is not empty ( And isEmpty contrary ):null、"" by false , For the other true
System.out.println(StringUtils.isNotEmpty(null)); // false
System.out.println(StringUtils.isNotEmpty("")); // false
System.out.println(StringUtils.isNotEmpty(" ")); // true
System.out.println(StringUtils.isNotEmpty(" zibo ")); // true
Two 、 Judgment type
5、 Determine whether the string is a number , Don't ignore spaces
// 5、 Determine whether the string is a number , Don't ignore spaces
System.out.println(StringUtils.isNumeric("")); // false
System.out.println(StringUtils.isNumeric(" ")); // false
System.out.println(StringUtils.isNumeric("100")); // true
System.out.println(StringUtils.isNumeric(" 100 ")); // false
// Note that the following even decimals also return `false` , This is something I didn't expect !
System.out.println(StringUtils.isNumeric("100.0")); // false
6、 Determine whether the string is a number , Ignore spaces
// 6、 Determine whether the string is a number , Ignore spaces
// Empty string returns `true` , I was stunned !
System.out.println(StringUtils.isNumericSpace("")); // true
// Space string return `true` , I was stunned !
System.out.println(StringUtils.isNumericSpace(" ")); // true
System.out.println(StringUtils.isNumericSpace("100")); // true
System.out.println(StringUtils.isNumericSpace(" 100 ")); // true
// Note that the following even decimals also return `false` , This is something I didn't expect !
System.out.println(StringUtils.isNumericSpace("100.0")); // false
7、 Determine whether the string is a Greek letter , Don't ignore spaces
// 7、 Determine whether the string is a Greek letter , Don't ignore spaces
// The Greek letter ? I'm afraid I won't use this function for 10000 years !
System.out.println(StringUtils.isAlpha("")); // false
System.out.println(StringUtils.isAlpha(" ")); // false
System.out.println(StringUtils.isAlpha("zibo")); // true
System.out.println(StringUtils.isAlpha(" zibo ")); // false
System.out.println(StringUtils.isAlpha("zibo zibo")); // false
System.out.println(StringUtils.isAlpha("zibo123")); // false
8、 Determine whether the string is a Greek letter , Ignore spaces
// 8、 Determine whether the string is a Greek letter , Ignore spaces
// It is also an empty string , Ignore spaces and return `true` , I was stunned ! Is there a difference !
System.out.println(StringUtils.isAlphaSpace("")); // true
System.out.println(StringUtils.isAlphaSpace(" ")); // true
System.out.println(StringUtils.isAlphaSpace("zibo")); // true
System.out.println(StringUtils.isAlphaSpace(" zibo ")); // true
System.out.println(StringUtils.isAlphaSpace("zibo zibo")); // true
System.out.println(StringUtils.isAlphaSpace("zibo123")); // false
9、 Judge whether the string is composed of Greek letters and numbers , Don't ignore spaces
// 9、 Judge whether the string is composed of Greek letters and numbers , Don't ignore spaces
// It's another function that won't be used in 10000 years !
System.out.println(StringUtils.isAlphanumeric("")); // false
System.out.println(StringUtils.isAlphanumeric(" ")); // false
// thus it can be seen , This is an inclusive relationship ! Letters and numbers are not required , One of them also returns `true` !
System.out.println(StringUtils.isAlphanumeric("zibo")); // true
System.out.println(StringUtils.isAlphanumeric("123")); // true
System.out.println(StringUtils.isAlphanumeric("zibo123")); // true
System.out.println(StringUtils.isAlphanumeric("zibo123 ")); // false
10、 Judge whether the string is composed of Greek letters and numbers , Ignore spaces
// 10、 Judge whether the string is composed of Greek letters and numbers , Ignore spaces
// It is also an empty string , Ignore spaces and return `true` , I was stunned ! Is there a difference !
System.out.println(StringUtils.isAlphanumericSpace("")); // true
System.out.println(StringUtils.isAlphanumericSpace(" ")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo")); // true
System.out.println(StringUtils.isAlphanumericSpace("123")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo123")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo123 ")); // true
3、 ... and 、 Determine case
11、 Determine whether the string is all lowercase
// 11、 Determine whether the string is all lowercase
System.out.println(StringUtils.isAllLowerCase("zibo")); // true
System.out.println(StringUtils.isAllLowerCase("ZiBo")); // false
System.out.println(StringUtils.isAllLowerCase("ZIBO")); // false
12、 Determine whether the string is all capital letters
// 12、 Determine whether the string is all capital letters
System.out.println(StringUtils.isAllUpperCase("ZIBO")); // true
System.out.println(StringUtils.isAllUpperCase("ZiBo")); // false
System.out.println(StringUtils.isAllUpperCase("zibo")); // false
Four 、 Judgment includes
13、 Judge whether the source string contains the target string
// 13、 Judge whether the source string contains the target string
System.out.println(StringUtils.contains("zibo", "zibo")); // true
// so , Case sensitive !
System.out.println(StringUtils.contains("zibo", "ZIBO")); // false
System.out.println(StringUtils.contains("zibo", "")); // true
// Don't ignore spaces , return `false` !
System.out.println(StringUtils.contains("zibo", " ")); // false
14、 Determine whether the source string contains the destination byte
// 14、 Determine whether the source string contains the destination byte
System.out.println(StringUtils.contains("zibo", 'z')); // true
// so , Case sensitive !
System.out.println(StringUtils.contains("zibo", 'Z')); // false
System.out.println(StringUtils.contains("zibo", 'a')); // false
15、 Judge whether the source string contains the target string ( Multiple goals )
// 15、 Judge whether the source string contains the target string ( Multiple goals )
System.out.println(StringUtils.containsAny("zibo", "zibo")); // true
// Multiple target strings
System.out.println(StringUtils.containsAny("zibo", "zi", "bo")); // true
// so , Case sensitive !
System.out.println(StringUtils.containsAny("zibo", "ZIBO")); // false
16、 Determine whether the source string contains the destination byte ( Multiple goals )
// 16、 Determine whether the source string contains the destination byte ( Multiple goals )
// Multiple target strings
System.out.println(StringUtils.containsAny("zibo", 'z')); // true
System.out.println(StringUtils.containsAny("zibo", 'z', 'b')); // true
// unexpected : There is a , Also returned `true` !
System.out.println(StringUtils.containsAny("zibo", 'z', 'a')); // true
System.out.println(StringUtils.containsAny("zibo", 'a')); // false
5、 ... and 、 Space before and after
17、 Remove the space before and after the string (““ return ””)
// 17、 Remove the space before and after the string ("" return "")
// If it is null, it returns null , by null When to return to null( It's not a string null, Prevent null pointer exception )
System.out.println(StringUtils.trim(null)); // null
System.out.println(StringUtils.trim(" zibo ")); // zibo
System.out.println(StringUtils.trim(" ")); // ""
18、 Remove the space before and after the string ("" return null )
// 18、 Remove the space before and after the string ("" return `null` )
// When empty , return null( It's not a string null, Prevent null pointer exception )
System.out.println(StringUtils.trimToNull(null)); // null
System.out.println(StringUtils.trimToNull(" zibo ")); // zibo
System.out.println(StringUtils.trimToNull(" ")); // null
19、 Remove the space before and after the string (null return "" )
// 19、 Remove the space before and after the string (null return "" )
System.out.println(StringUtils.trimToEmpty(null)); // ""
System.out.println(StringUtils.trimToEmpty(" zibo ")); // zibo
System.out.println(StringUtils.trimToEmpty(" ")); // ""
6、 ... and 、 Determine whether two strings are equal
20、 Compare two strings for equality ( Case sensitive )
// 20、 Compare two strings for equality ( Case sensitive )
System.out.println(StringUtils.equals("zibo", "zibo")); // true
System.out.println(StringUtils.equals("zibo", "ZIBO")); // false
21、 Compare two strings for equality ( Ignore case )
// 21、 Compare two strings for equality ( Ignore case )
System.out.println(StringUtils.equalsIgnoreCase("zibo", "zibo")); // true
System.out.println(StringUtils.equalsIgnoreCase("zibo", "ZIBO")); // true
7、 ... and 、 Find the target string location
22、 Find the position where the target string first appears in the source string , No return -1
// 22、 Find the position where the target string first appears in the source string , No return -1
System.out.println(StringUtils.indexOf("zibo", "z")); // 0
System.out.println(StringUtils.indexOf("zibo", "a")); // -1
23、 Find the position where the target string first appears in the source string , No return -1( Start at the specified location )
// 23、 Find the position where the target string first appears in the source string , No return -1( Start at the specified location )
System.out.println(StringUtils.indexOf("zibo", "i", 0)); // 1
System.out.println(StringUtils.indexOf("zibo", "i", 1)); // 1
System.out.println(StringUtils.indexOf("zibo", "i", 2)); // -1
24、 Find the index position of any element in the array in the source string , Meet multiple hours , Minimum value , No return -1( Multiple goals )
// 24、 Find the index position of any element in the array in the source string , Meet multiple hours , Minimum value , No return -1( Multiple goals )
System.out.println(StringUtils.indexOfAny("zibo", "z", "i")); // 0
System.out.println(StringUtils.indexOfAny("zibo", "b", "o")); // 2
System.out.println(StringUtils.indexOfAny("zibo", "b", "t")); // 2
8、 ... and 、 toggle case
25、 String letter to lowercase
// 25、 String letter to lowercase
System.out.println(StringUtils.lowerCase("ZIBO")); // zibo
26、 String letters to uppercase
// 26、 String letters to uppercase
System.out.println(StringUtils.upperCase("zibo")); // ZIBO
27、 Capitalize the initial
// 28、 Capitalize the initial
System.out.println(StringUtils.capitalize("zibo")); // Zibo
Nine 、 Omission and supplement
28、 Yes str The string is abbreviated by ellipsis
// 27、 Yes str The string is abbreviated by ellipsis
// maxWidth Length , Must be greater than or equal to 4( Indicates the length after abbreviation )
System.out.println(StringUtils.abbreviate("zibo zibo zibo", 4)); // z...
29、 take str Fill in blanks before and after , Bring the total length to size
// 29、 take str Fill in blanks before and after , Bring the total length to size
// size Itself is less than str Length , No filling
System.out.println(StringUtils.center("zibo", 6)); // " zibo "
30、 Fill with the specified string
// 30、 Fill with the specified string
System.out.println(StringUtils.center("zibo", 6, "*")); // "*zibo*"
Ten 、 Compare strings
31、 Compare strings str1 And str2 Size ( Case sensitive )
// 31、 Compare strings str1 And str2 Size ( Case sensitive )
System.out.println(StringUtils.compare("a", "a")); // 0
System.out.println(StringUtils.compare("a", "b")); // -1
System.out.println(StringUtils.compare("b", "a")); // 1
System.out.println(StringUtils.compare("a", "A")); // 32
32、 Compare strings str1 And str2 Size ( Ignore case )
// 32、 Compare strings str1 And str2 Size ( Ignore case )
System.out.println(StringUtils.compareIgnoreCase("a", "A")); // 0
System.out.println(StringUtils.compareIgnoreCase("a", null, true)); // 1
System.out.println(StringUtils.compareIgnoreCase(null, null, true)); // 0
System.out.println(StringUtils.compareIgnoreCase("a", null, false)); // -1
System.out.println(StringUtils.compareIgnoreCase(null, null, false)); // 0
System.out.println(StringUtils.compareIgnoreCase("z", null, true)); // 1
System.out.println(StringUtils.compareIgnoreCase("z", null, false)); // -1
11、 ... and 、 Find the number of occurrences
33、 Find a target character / The number of times the string appears in the source string
// 33、 Find a target character / The number of times the string appears in the source string
System.out.println(StringUtils.countMatches("zibo zibo zibo", "z")); // 3
Twelve 、 The separator separates
34、 Connect the array with the specified separator
// 34、 Connect the array with the specified separator
// liubei,guanyu,zhangfei
System.out.println(StringUtils.join(new String[]{
"liubei", "guanyu", "zhangfei"}, ","));
System.out.println(StringUtils.join("a", "b", "c")); // abc
System.out.println(StringUtils.join(Arrays.asList("a", "b", "c"), ",")); // a,b,c
// [a, b, c],[d, e, f]
System.out.println(StringUtils.joinWith(",", Arrays.asList("a", "b", "c"), Arrays.asList("d", "e", "f")));
13、 ... and 、 Null, default value
35、 If the string is null 、“”、 " ", Returns the default string
// 35、 If the string is null 、""、 " ", Returns the default string
System.out.println(StringUtils.defaultIfBlank(null, "default")); // default
System.out.println(StringUtils.defaultIfBlank("", "default")); // default
System.out.println(StringUtils.defaultIfBlank(" ", "default")); // default
36、 If the string is null 、“” , Returns the default string
// 36、 If the string is null 、"" , Returns the default string
System.out.println(StringUtils.defaultIfEmpty(null, "default")); // default
System.out.println(StringUtils.defaultIfEmpty("", "default")); // default
System.out.println(StringUtils.defaultIfEmpty(" ", "default")); // " "
fourteen 、 Complete code
package com.zibo.zibo2022.string_utils.main;
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
// start
// 1、 Determines if the string is empty :null、""、" " by true , For the other false
System.out.println(StringUtils.isBlank(null)); // true
System.out.println(StringUtils.isBlank("")); // true
System.out.println(StringUtils.isBlank(" ")); // true
System.out.println(StringUtils.isBlank(" zibo ")); // false
// 2、 Determine if the string is not empty ( And isBlank contrary ):null、""、" " by false , For the other true
System.out.println(StringUtils.isNotBlank(null)); // true
System.out.println(StringUtils.isNotBlank("")); // true
System.out.println(StringUtils.isNotBlank(" ")); // true
System.out.println(StringUtils.isNotBlank(" zibo ")); // true
// 3、 Determines if the string is empty :null、"" by true , For the other false
System.out.println(StringUtils.isEmpty(null)); // true
System.out.println(StringUtils.isEmpty("")); // true
System.out.println(StringUtils.isEmpty(" ")); // false
System.out.println(StringUtils.isEmpty(" zibo ")); // false
// 4、 Determine if the string is not empty ( And isEmpty contrary ):null、"" by false , For the other true
System.out.println(StringUtils.isNotEmpty(null)); // false
System.out.println(StringUtils.isNotEmpty("")); // false
System.out.println(StringUtils.isNotEmpty(" ")); // true
System.out.println(StringUtils.isNotEmpty(" zibo ")); // true
// 5、 Determine whether the string is a number , Don't ignore spaces
System.out.println(StringUtils.isNumeric("")); // false
System.out.println(StringUtils.isNumeric(" ")); // false
System.out.println(StringUtils.isNumeric("100")); // true
System.out.println(StringUtils.isNumeric(" 100 ")); // false
// Note that the following even decimals also return `false` , This is something I didn't expect !
System.out.println(StringUtils.isNumeric("100.0")); // false
// 6、 Determine whether the string is a number , Ignore spaces
// Empty string returns `true` , I was stunned !
System.out.println(StringUtils.isNumericSpace("")); // true
// Space string return `true` , I was stunned !
System.out.println(StringUtils.isNumericSpace(" ")); // true
System.out.println(StringUtils.isNumericSpace("100")); // true
System.out.println(StringUtils.isNumericSpace(" 100 ")); // true
// Note that the following even decimals also return `false` , This is something I didn't expect !
System.out.println(StringUtils.isNumericSpace("100.0")); // false
// 7、 Determine whether the string is a Greek letter , Don't ignore spaces
// The Greek letter ? I'm afraid I won't use this function for 10000 years !
System.out.println(StringUtils.isAlpha("")); // false
System.out.println(StringUtils.isAlpha(" ")); // false
System.out.println(StringUtils.isAlpha("zibo")); // true
System.out.println(StringUtils.isAlpha(" zibo ")); // false
System.out.println(StringUtils.isAlpha("zibo zibo")); // false
System.out.println(StringUtils.isAlpha("zibo123")); // false
// 8、 Determine whether the string is a Greek letter , Ignore spaces
// It is also an empty string , Ignore spaces and return `true` , I was stunned ! Is there a difference !
System.out.println(StringUtils.isAlphaSpace("")); // true
System.out.println(StringUtils.isAlphaSpace(" ")); // true
System.out.println(StringUtils.isAlphaSpace("zibo")); // true
System.out.println(StringUtils.isAlphaSpace(" zibo ")); // true
System.out.println(StringUtils.isAlphaSpace("zibo zibo")); // true
System.out.println(StringUtils.isAlphaSpace("zibo123")); // false
// 9、 Judge whether the string is composed of Greek letters and numbers , Don't ignore spaces
// It's another function that won't be used in 10000 years !
System.out.println(StringUtils.isAlphanumeric("")); // false
System.out.println(StringUtils.isAlphanumeric(" ")); // false
// thus it can be seen , This is an inclusive relationship ! Letters and numbers are not required , One of them also returns `true` !
System.out.println(StringUtils.isAlphanumeric("zibo")); // true
System.out.println(StringUtils.isAlphanumeric("123")); // true
System.out.println(StringUtils.isAlphanumeric("zibo123")); // true
System.out.println(StringUtils.isAlphanumeric("zibo123 ")); // false
// 10、 Judge whether the string is composed of Greek letters and numbers , Ignore spaces
// It is also an empty string , Ignore spaces and return `true` , I was stunned ! Is there a difference !
System.out.println(StringUtils.isAlphanumericSpace("")); // true
System.out.println(StringUtils.isAlphanumericSpace(" ")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo")); // true
System.out.println(StringUtils.isAlphanumericSpace("123")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo123")); // true
System.out.println(StringUtils.isAlphanumericSpace("zibo123 ")); // true
// 11、 Determine whether the string is all lowercase
System.out.println(StringUtils.isAllLowerCase("zibo")); // true
System.out.println(StringUtils.isAllLowerCase("ZiBo")); // false
System.out.println(StringUtils.isAllLowerCase("ZIBO")); // false
// 12、 Determine whether the string is all capital letters
System.out.println(StringUtils.isAllUpperCase("ZIBO")); // true
System.out.println(StringUtils.isAllUpperCase("ZiBo")); // false
System.out.println(StringUtils.isAllUpperCase("zibo")); // false
// 13、 Judge whether the source string contains the target string
System.out.println(StringUtils.contains("zibo", "zibo")); // true
// so , Case sensitive !
System.out.println(StringUtils.contains("zibo", "ZIBO")); // false
System.out.println(StringUtils.contains("zibo", "")); // true
// Don't ignore spaces , return `false` !
System.out.println(StringUtils.contains("zibo", " ")); // false
// 14、 Determine whether the source string contains the destination byte
System.out.println(StringUtils.contains("zibo", 'z')); // true
// so , Case sensitive !
System.out.println(StringUtils.contains("zibo", 'Z')); // false
System.out.println(StringUtils.contains("zibo", 'a')); // false
// 15、 Judge whether the source string contains the target string ( Multiple goals )
System.out.println(StringUtils.containsAny("zibo", "zibo")); // true
// Multiple target strings
System.out.println(StringUtils.containsAny("zibo", "zi", "bo")); // true
// so , Case sensitive !
System.out.println(StringUtils.containsAny("zibo", "ZIBO")); // false
// 16、 Determine whether the source string contains the destination byte ( Multiple goals )
// Multiple target strings
System.out.println(StringUtils.containsAny("zibo", 'z')); // true
System.out.println(StringUtils.containsAny("zibo", 'z', 'b')); // true
// unexpected : There is a , Also returned `true` !
System.out.println(StringUtils.containsAny("zibo", 'z', 'a')); // true
System.out.println(StringUtils.containsAny("zibo", 'a')); // false
// 17、 Remove the space before and after the string ("" return "")
// If it is null, it returns null , by null When to return to null( It's not a string null, Prevent null pointer exception )
System.out.println(StringUtils.trim(null)); // null
System.out.println(StringUtils.trim(" zibo ")); // zibo
System.out.println(StringUtils.trim(" ")); // ""
// 18、 Remove the space before and after the string ("" return `null` )
// When empty , return null( It's not a string null, Prevent null pointer exception )
System.out.println(StringUtils.trimToNull(null)); // null
System.out.println(StringUtils.trimToNull(" zibo ")); // zibo
System.out.println(StringUtils.trimToNull(" ")); // null
// 19、 Remove the space before and after the string (null return "" )
System.out.println(StringUtils.trimToEmpty(null)); // ""
System.out.println(StringUtils.trimToEmpty(" zibo ")); // zibo
System.out.println(StringUtils.trimToEmpty(" ")); // ""
// 20、 Compare two strings for equality ( Case sensitive )
System.out.println(StringUtils.equals("zibo", "zibo")); // true
System.out.println(StringUtils.equals("zibo", "ZIBO")); // false
// 21、 Compare two strings for equality ( Ignore case )
System.out.println(StringUtils.equalsIgnoreCase("zibo", "zibo")); // true
System.out.println(StringUtils.equalsIgnoreCase("zibo", "ZIBO")); // true
// 22、 Find the position where the target string first appears in the source string , No return -1
System.out.println(StringUtils.indexOf("zibo", "z")); // 0
System.out.println(StringUtils.indexOf("zibo", "a")); // -1
// 23、 Find the position where the target string first appears in the source string , No return -1( Start at the specified location )
System.out.println(StringUtils.indexOf("zibo", "i", 0)); // 1
System.out.println(StringUtils.indexOf("zibo", "i", 1)); // 1
System.out.println(StringUtils.indexOf("zibo", "i", 2)); // -1
// 24、 Find the index position of any element in the array in the source string , Meet multiple hours , Minimum value , No return -1( Multiple goals )
System.out.println(StringUtils.indexOfAny("zibo", "z", "i")); // 0
System.out.println(StringUtils.indexOfAny("zibo", "b", "o")); // 2
System.out.println(StringUtils.indexOfAny("zibo", "b", "t")); // 2
// 25、 String letter to lowercase
System.out.println(StringUtils.lowerCase("ZIBO")); // zibo
// 26、 String letters to uppercase
System.out.println(StringUtils.upperCase("zibo")); // ZIBO
// 27、 Yes str The string is abbreviated by ellipsis
// maxWidth Length , Must be greater than or equal to 4( Indicates the length after abbreviation )
System.out.println(StringUtils.abbreviate("zibo zibo zibo", 4)); // z...
// 28、 Capitalize the initial
System.out.println(StringUtils.capitalize("zibo")); // Zibo
// 29、 take str Fill in blanks before and after , Bring the total length to size
// size Itself is less than str Length , No filling
System.out.println(StringUtils.center("zibo", 6)); // " zibo "
// 30、 Fill with the specified string
System.out.println(StringUtils.center("zibo", 6, "*")); // "*zibo*"
// 31、 Compare strings str1 And str2 Size ( Case sensitive )
System.out.println(StringUtils.compare("a", "a")); // 0
System.out.println(StringUtils.compare("a", "b")); // -1
System.out.println(StringUtils.compare("b", "a")); // 1
System.out.println(StringUtils.compare("a", "A")); // 32
// 32、 Compare strings str1 And str2 Size ( Ignore case )
System.out.println(StringUtils.compareIgnoreCase("a", "A")); // 0
System.out.println(StringUtils.compareIgnoreCase("a", null, true)); // 1
System.out.println(StringUtils.compareIgnoreCase(null, null, true)); // 0
System.out.println(StringUtils.compareIgnoreCase("a", null, false)); // -1
System.out.println(StringUtils.compareIgnoreCase(null, null, false)); // 0
System.out.println(StringUtils.compareIgnoreCase("z", null, true)); // 1
System.out.println(StringUtils.compareIgnoreCase("z", null, false)); // -1
// 33、 Find a target character / The number of times the string appears in the source string
System.out.println(StringUtils.countMatches("zibo zibo zibo", "z")); // 3
// 34、 Connect the array with the specified separator
// liubei,guanyu,zhangfei
System.out.println(StringUtils.join(new String[]{
"liubei", "guanyu", "zhangfei"}, ","));
System.out.println(StringUtils.join("a", "b", "c")); // abc
System.out.println(StringUtils.join(Arrays.asList("a", "b", "c"), ",")); // a,b,c
// [a, b, c],[d, e, f]
System.out.println(StringUtils.joinWith(",", Arrays.asList("a", "b", "c"), Arrays.asList("d", "e", "f")));
// 35、 If the string is null 、""、 " ", Returns the default string
System.out.println(StringUtils.defaultIfBlank(null, "default")); // default
System.out.println(StringUtils.defaultIfBlank("", "default")); // default
System.out.println(StringUtils.defaultIfBlank(" ", "default")); // default
// 36、 If the string is null 、"" , Returns the default string
System.out.println(StringUtils.defaultIfEmpty(null, "default")); // default
System.out.println(StringUtils.defaultIfEmpty("", "default")); // default
System.out.println(StringUtils.defaultIfEmpty(" ", "default")); // " "
// end
}
}
边栏推荐
- DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class
- Cloud function realizes website automatic check-in configuration details [web function /nodejs/cookie]
- Matlab02: structured programming and function definition "suggestions collection"
- [basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)
- Isolation level of MySQL, possible problems (dirty reading, unrepeatable reading, phantom reading) and their solutions
- redis版本怎么查看(查看redis进程)
- SQL server only has database files and no log files. The solution to the 1813 error in restoring data times
- 🧐 Table1 | finish your third line watch in one second
- andriod6.0低功耗模式(关闭wifi、蓝牙、gps、屏幕亮度等)
- Minimum dominating set (MDS) and its matlab code
猜你喜欢

数仓搭建——ADS层

Huawei releases harmonyos 3.0, taking another step towards "Internet of all things"

从零开始实现lmax-Disruptor队列(六)Disruptor 解决伪共享、消费者优雅停止实现原理解析
![[Yugong series] go teaching course in July 2022, an array of 020 go containers](/img/06/b2f69599b30c4a93a6240613cbee84.png)
[Yugong series] go teaching course in July 2022, an array of 020 go containers

AQS原理

【AD学习】本次海上航行器大赛画pcb图的历程

追踪伦敦银实时行情的方法

Wechat campus bathroom reservation applet graduation design finished product (5) assignment

Summary of preprocessing methods for time series data

时间序列数据的预处理方法总结
随机推荐
MATLAB02:结构化编程和函数定义「建议收藏」
Method of converting inline elements to block elements
iNFTnews | 元宇宙购物体验将成为吸引消费者的一大利器
Matlab02: structured programming and function definition "suggestions collection"
C语言括号匹配(栈括号匹配c语言)
Protective copy & stateless
如何给女友讲明白JS的bind模拟实现
Outlier detection and open set identification (1)
散列表 ~
Error reporting: Rong Lianyun sends SMS verification code message 500
关于ThreadPool的一些注意事项
Flash and seven cattle cloud upload pictures
快手重点整治搬运、洗稿等方式的养号行为,自媒体平台如何净化内容生态
I don't recommend you use Select*
B- 树 ~
机器学习 | MATLAB实现RBF径向基神经网络newrbe参数设定
Some considerations about ThreadPool
数学建模及其基础知识详解(化学常考知识点)
Isolation level of MySQL, possible problems (dirty reading, unrepeatable reading, phantom reading) and their solutions
Outlier detection and open set identification (2)