Instructions for the use of commons.lang3

Posted by kennethl on Mon, 23 Sep 2019 07:19:45 +0200

ArchUtils (System Information Tool Class for Java Running Environment)

  1. getArch(); // Get 32 bit, 64 bit, unknown computer processor architecture

  2. getType(); // Returns processor types x86, ia64, ppc, unknown

  3. is32Bit(); // Check if the processor is 32 bits

  4. is64Bit(); // / Check whether the processor is 64 bits

  5. isIA64(); // Check if it is Intel Anden processor type

  6. isPPC(); // Check if the processor is a power PC type

  7. isX86(); // / Check if the processor is x86 type

  • ArrayUtils (Array Tool Class)

1.add(boolean[] array, boolean element) adds the given data to the specified array and returns a new array

 Eg:  
		ArrayUtils.add(null, true) = [true]
		 ArrayUtils.add([true], false) = [true, false]
		 ArrayUtils.add([true, false], true) = [true, false, true]

2.add(boolean[] array, int index, boolean element) adds the given data to the specified array subscript and returns a new array.

Eg:  
			ArrayUtils.add(null, 0, true) = [true]
			ArrayUtils.add([false], 1, true) = [false, true]
			ArrayUtils.add([true, false], 1, true) = [true, true, false]
			byte, int, char, double, float, int, long ,short, T[] Empathy

3.addAll(boolean[] array1, boolean... Aray2) Adds a given number of data to a specified array and returns a new array

Eg:
				ArrayUtils.addAll(array1, null) = cloned copy of array1
				ArrayUtils.addAll(null, array2) = cloned copy of array2
				ArrayUtils.addAll([], []) = []
				byte, int, char, double, float, int, long ,short, T[] Empathy

4.clone(boolean[] array) replicates the array and returns the result array empty, which returns empty

byte, int, char, double, float, int, long ,short, T[] Empathy

5.contains(boolean[] array, boolean valueToFind) checks whether the data exists in the array and returns a Boolean value

byte, int, char, double, float, int, long ,short, Object Empathy

6.getLength(Object array) returns the array length

Eg:
			ArrayUtils.getLength(null) = 0
			ArrayUtils.getLength([]) = 0
			ArrayUtils.getLength([null]) = 1
			ArrayUtils.getLength([true, false]) = 2
			ArrayUtils.getLength([1, 2, 3]) = 3
			ArrayUtils.getLength(["a", "b", "c"]) = 3
			hashCode(Object array) Returns the hash of the array Code code

7.indexOf(boolean[] array, boolean valueToFind) starts from the first bit of the array to query whether there is a specified value in the array, and there is a value that returns index, otherwise it returns - 1.

8.indexOf(boolean[] array, boolean valueToFind, int startIndex) starts from the startIndex bit of the array to query whether there is a specified value in the array, and there is a value that returns index, otherwise it returns -1.

byte, int, char, double, float, int, long ,short Empathy

9.insert(int index, boolean[] array, boolean... values) Adds the specified element to the array at the specified location, returning a new array

Eg:
			ArrayUtils.insert(index, null, null) = null
			ArrayUtils.insert(index, array, null) = cloned copy of 'array'
			ArrayUtils.insert(index, null, values) = null
			byte, int, char, double, float, int, long ,short, T[] Empathy

10.isEmpty(boolean[] array) determines whether the array is empty and returns a Boolean value

byte, int, char, double, float, int, long ,short, Object Empathy

11.isNotEmpty(boolean[] array) determines whether the array is empty, not null

byte, int, char, double, float, int, long ,short, T[] Empathy

12. isSame Length (boolean [] array1, Boolean [] array2) determines whether the length of two arrays is the same, when the array is empty-view length 0. Returns a Boolean value

13.isSameType(Object array1, Object array2) determines whether the two arrays are of the same type and returns a boolean value

14.isSorted(boolean[] array) determines whether the array is sorted in natural order and returns a Boolean value

byte, int, char, double, float, int, long ,short, T[] Empathy

15.isSorted(T[] array, Comparator comparator) determines whether the array is sorted in comparator order and returns a boolean value

16.lastIndexOf(boolean[] array, boolean valueToFind) queries from the last bit of the array to see if there is a specified value in the array, and if there is a value returning index, otherwise it returns -1.

17.lastIndexOf(boolean[] array, boolean valueToFind, int startIndex) queries from the last startIndex bit of the array to see if there is a specified value in the array, and if there is a value returning index, it returns -1 otherwise.

byte, int, char, double, float, int, long ,short, Object Empathy

18.nullToEmpty(boolean[] array) converts null to an empty array, returns the original array if the array is not null, and returns an empty array if the array is null.

byte, int, char, double, float, int, long ,short, Object, T Empathy

19.remove(boolean[] array, int index) deletes elements at the specified location of the array, returns a new array, and moves all subsequent elements left (subscript minus 1)

Eg:
		ArrayUtils.remove([true], 0) = []
		ArrayUtils.remove([true, false], 0) = [false]
		ArrayUtils.remove([true, false], 1) = [true]
		ArrayUtils.remove([true, true, false], 1) = [true, false]
		byte, int, char, double, float, int, long ,short, T[] Empathy

20.removeAll(boolean[] array, int... indices) Deletes the elements at multiple specified positions in the array, returns a new array, and moves all subsequent elements left (subscript minus 1)

Eg:
			ArrayUtils.removeAll([true, false, true], 0, 2) = [false]
			ArrayUtils.removeAll([true, false, true], 1, 2) = [true]
			byte, int, char, double, float, int, long ,short, T[] Empathy

21.removeAllOccurences(boolean[] array, boolean element) deletes the specified element from the array and returns a new array

byte, int, char, double, float, int, long ,short, T[] Empathy

22.removeElement(boolean[] array, boolean element) deletes the specified element from the array and returns a new array

byte, int, char, double, float, int, long ,short, T[] Empathy

23.removeElements(boolean[] array, boolean... values) Remove a specified number of elements from the array and return a new array

Eg:
		ArrayUtils.removeElements(null, true, false) = null
		ArrayUtils.removeElements([], true, false) = []
		ArrayUtils.removeElements([true], false, false) = [true]
		
		ArrayUtils.removeElements([true, false], true, true) = [false]
		ArrayUtils.removeElements([true, false, true], true) = [false, true]
		ArrayUtils.removeElements([true, false, true], true, true) = [false]
		byte, int, char, double, float, int, long ,short, T[] Empathy

24.reverse(boolean[] array) array inversion

25. Reverse (boolean [] array, int start IndexInclusive, int end IndexExclusive) array is inverted from a specified location interval

byte, int, char, double, float, int, long ,short, Object Empathy

26.shuffle(boolean[] array) rearranges elements in an array in random order

byte, int, char, double, float, int, long ,short, Object Empathy

27. Subarray (boolean [] array, int start IndexInclusive, int end IndexExclusive) intercepts arrays, intercepts arrays by a specified location interval, and returns a new array

byte, int, char, double, float, int, long ,short, T[] Empathy

28.swap(boolean[] array, int offset1, int offset2) specifies the exchange of elements between two locations of the array

Eg:
ArrayUtils.swap([1, 2, 3], 0, 2) -> [3, 2, 1]
ArrayUtils.swap([1, 2, 3], 0, 0) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], 1, 0) -> [2, 1, 3]
ArrayUtils.swap([1, 2, 3], 0, 5) -> [1, 2, 3]
ArrayUtils.swap([1, 2, 3], -1, 1) -> [2, 1, 3]
byte, int, char, double, float, int, long ,short, Object Empathy

29. to Array (T... items) Create arrays

Eg:
String[] array = ArrayUtils.toArray("1", "2");
String[] emptyArray = ArrayUtils.<String>toArray();

30.toMap(Object[] array) converts two-dimensional arrays into Maps and returns to Maps

Eg:
Map colorMap = ArrayUtils.toMap(new String[][] {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}}
);

31.toObject(boolean[] array) converts an array of primitive types into an array of object types and returns

byte, int, char, double, float, int, long ,short Empathy

32.toPrimitive(Boolean[] array) converts an array of object types into an array of primitive types and returns

byte, int, char, double, float, int, long ,short Empathy

33.toString(Object array) converts an array to a string string string and returns it

34.toStringArray(Object[] array) converts an Object array to a String array type

  • Boolean Utils

1.and(boolean... array) logic and

Eg:
        BooleanUtils.and(true, true) = true
	    BooleanUtils.and(false, false) = false
	    BooleanUtils.and(true, false) = false
	    BooleanUtils.and(true, true, false) = false
	    BooleanUtils.and(true, true, true) = true

2.compare(boolean x, boolean y) compares two Boolean values and returns int type if x = y returns 0,! X & Y returns less than 0, X & Y returns more than 0

3. Is isFalse (boolean bool) false and returns boolean

4. Is isTrue (boolean bool) true and returns boolean

5.negate(Boolean bool) Logical Non-

Eg:
    BooleanUtils.negate(Boolean.TRUE)  = Boolean.FALSE;
    BooleanUtils.negate(Boolean.FALSE)  = Boolean.TRUE;
    BooleanUtils.negate(null)  = null;

6.or(boolean... array) logic or

  Eg:
        BooleanUtils.or(true, true) = true
	    BooleanUtils.or(false, false) = false
	    BooleanUtils.or(true, false) = true
	    BooleanUtils.or(true, true, false) = true
	    BooleanUtils.or(true, true, true) = true
	    BooleanUtils.or(false, false, false) = false

7.toBoolean(Boolean bool) converts object types to basic data types and returns

 Eg:
        BooleanUtils.toBoolean(Boolean.TRUE)  = true
	    BooleanUtils.toBoolean(Boolean.FALSE) = false
	    BooleanUtils.toBoolean(null) = false

8.toBoolean(int value) converts int type to boolean type and returns

    Eg: 
        BooleanUtils.toBoolean(0) = false
	    BooleanUtils.toBoolean(1) = true
	    BooleanUtils.toBoolean(2) = true

9.toBoolean(String str) converts string type to boolean type and returns

     Eg:
            BooleanUtils.toBoolean(null) = false
		    BooleanUtils.toBoolean("true") = true
		    BooleanUtils.toBoolean("TRUE") = true
		    BooleanUtils.toBoolean("tRUe") = true
		    BooleanUtils.toBoolean("on") = true
		    BooleanUtils.toBoolean("yes") = true
		    BooleanUtils.toBoolean("false") = false
		    BooleanUtils.toBoolean("x gti") = false
		    BooleanUtils.toBooleanObject("y") = true
		    BooleanUtils.toBooleanObject("n") = false
		    BooleanUtils.toBooleanObject("t") = true
		    BooleanUtils.toBooleanObject("f") = false

10.toInteger(boolean bool) converts boolean type data to int type and returns

 Eg:
      BooleanUtils.toInteger(true) = 1
      BooleanUtils.toInteger(false) = 0

11.toStringOnOff(boolean bool) converts boolean type data to String type'on'or'off'and returns

   Eg:  
	BooleanUtils.toStringOnOff(true)   = "on"
	BooleanUtils.toStringOnOff(false)  = "off"

12.toStringTrueFalse(Boolean bool) converts boolean type data to String type "true" or "false" and returns

 Eg:
        BooleanUtils.toStringTrueFalse(true)   = "true"
		BooleanUtils.toStringTrueFalse(false)  = "false"

13.toStringYesNo(boolean bool) converts boolean type data to String type'yes'or'no' and returns

     Eg:
          BooleanUtils.toStringYesNo(true)   = "yes"
		  BooleanUtils.toStringYesNo(false)  = "no"

14.xor(boolean... array) XOR

     Eg:
            BooleanUtils.xor(true, true) = false
		    BooleanUtils.xor(false, false) = false
		    BooleanUtils.xor(true, false) = true

ClassPath Untils

1. To Fully QualifiedName (Class <?> context, String resourceName) returns a string stitched by the class package name + resourceName
Eg:

 ClassPathUtils.toFullyQualifiedName(StringUtils.class,"StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"

2. toFully Qualified Name (Package context, String resourceName) returns a string stitched by the class package name + resourceName

  Eg:    ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(),"StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"

3. toFully Qualified Path (Class <?> context, String resourceName) returns a string stitched by the class package name + resourceName

Eg:
        ClassPathUtils.toFullyQualifiedPath(StringUtils.class,"StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"

4. toFully Qualified Path (Package context, String resourceName) returns a string stitched by the class package name + resourceName

  Eg:
       ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"

EnumUntils

1.getEnum(Class enumClass, String enumName) returns an enumeration through the class, possibly empty
2.getEnumList(Class enumClass) returns an enumerated collection through a class
3.getEnumMap(Class enumClass) returns an enumerated map through the class
4.isValidEnum(Class enumClass, String enumName) verifies that enumName is in the enumeration and returns true false

Enumeration class
public enum EnumDemo {
    AA("1"), BB("2");
    private String value;
    EnumDemo(String value) {
        this.value = value;
    }

  public String getValue() {
        return value;
    }
}

//test
EnumDemo enumDemo = EnumUtils.getEnum(EnumDemo.class, "");
System.out.println(enumDemo);
System.out.println("-----");
List<EnumDemo> list = EnumUtils.getEnumList(EnumDemo.class);
for (EnumDemo a : list) {
    System.out.println(a + ":" + a.getValue());
}
System.out.println("-----");
Map<String, EnumDemo> enumMap = EnumUtils.getEnumMap(EnumDemo.class);
for (Map.Entry<String, EnumDemo> entry : enumMap.entrySet()) {
    Object key = entry.getKey();
    EnumDemo value = entry.getValue();
    System.out.println(key + ":" + value.getValue());
}
System.out.println("-----");
System.out.println(EnumUtils.isValidEnum(EnumDemo.class, "aa"));

output
AA
-----
AA:1
BB:2
-----
AA:1
BB:2
-----
False

* ObjectUntils(Object Tool Class)

1.allNotNull(Object... values) Check that all elements are empty and return a boolean

  Eg: 
      //If an element returns false for empty, all elements do not return true for empty or for empty

	    ObjectUtils.allNotNull(*)= true
	    ObjectUtils.allNotNull(*, *)= true
	    ObjectUtils.allNotNull(null) = false
	    ObjectUtils.allNotNull(null, null)= false
	    ObjectUtils.allNotNull(null, *) = false
	    ObjectUtils.allNotNull(*, null)= false
	    ObjectUtils.allNotNull(*, *, null, *) = false

2.anyNotNull(Object... values) Check whether the element is empty and return a boolean

   Eg:
      //If an element is not empty, return true
	    ObjectUtils.anyNotNull(*) = true
	    ObjectUtils.anyNotNull(*, null)= true
	    ObjectUtils.anyNotNull(null, *) = true
	    ObjectUtils.anyNotNull(null, null, *, *) = true
	    ObjectUtils.anyNotNull(null) = false
	    ObjectUtils.anyNotNull(null, null) = false

3.clone(T obj) copies an object and returns it
4.compare(T c1, T c2) compares two objects and returns an int value
5.defaultIfNull(T object, T defaultValue) Returns a default value if the object is empty
6. First NonNull (T... values) Returns the first non-empty value in the array
7. NotEqual (Object object 1, Object object 2) determines that two objects are not equal and returns a boolean

Random Untils

1.nextBoolean() returns a random boolean value
2.nextBytes(int count) returns a random byte array of a specified size
3.nextDouble() returns a random double value
4. NextDouble (double start Inclusive, double end Inclusive) returns a random double value of a specified range
5.nextFloat() returns a random float value
6. NextFloat (float start Inclusive, float end Inclusive) returns a random float value of a specified range
7.nextInt() returns a random int value
8. NextInt (int start Inclusive, int end Exclusive) returns a random int value of a specified range
9.nextLong() returns a random long value
10. NextLong (long start Inclusive, long end Exclusive) returns a random long value of a specified range

System Untils

1.FILE_ENCODING Return System Coding
2.IS_JAVA_1_1,... IS_JAVA_1_8, IS_JAVA_10, IS_JAVA_9 judge the java version and return a boolean
3.IS_OS_LINUX determines whether the system is linux and returns a boolean
4.IS_OS_MAC determines whether the system is a mac and returns a boolean
5.IS_OS_WINDOWS, IS_OS_WINDOWS_10, IS_OS_WINDOWS_2000, IS_OS_WINDOWS_2003, IS_OS_WINDOWS_2008, IS_OS_WINDOWS_7, IS_OS_WINDOWS_8, IS_OS_WINDOWS_95, IS_OS_WINDOWS_98, IS_OS_WINDOWS_XP judge whether the system is a boolean or not.
6.JAVA_CLASS_PATH Returns System CLASS_PATH Value
7.JAVA_CLASS_VERSION returns to the system java version
8.JAVA_HOME Returns System java home
9.JAVA_RUNTIME_VERSION returns to the running version of java
10.JAVA_VERSION returns to the java version
11.OS_NAME returns the system name
12.OS_VERSION Returns to System Version
13.USER_COUNTRY returns the user country number
14.USER_DIR returns to the project folder
15.USER_HOME returns to the system user home folder
16.USER_LANGUAGE Returns System User Language
17.USER_NAME returns the system username

9. String Untils (String Tool Class)

1.abbreviate(String str, int maxWidth) returns a string of specified length plus ellipsis, maxWidth must be greater than 3

  Eg:
       StringUtils.abbreviate(null, *)= null
	    StringUtils.abbreviate("", 4)  = ""
	    StringUtils.abbreviate("abcdefg", 6) = "abc..."
	    StringUtils.abbreviate("abcdefg", 7) = "abcdefg"
	    StringUtils.abbreviate("abcdefg", 8) = "abcdefg"
	    StringUtils.abbreviate("abcdefg", 4) = "a..."
	    StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException

2.abbreviate(String str, int offset, int maxWidth) returns a string of specified length plus ellipsis, maxWidth must be greater than 3

3. Abbreviate (String str, String abbrev Marker, int maxWidth) returns a specified length string with a custom ellipsis number, maxWidth must be greater than 3

 Eg:
       StringUtils.abbreviate(null, "...", *)       = null
	    StringUtils.abbreviate("abcdefg", null, *)  = "abcdefg"
	    StringUtils.abbreviate("", "...", 4)         = ""
	    StringUtils.abbreviate("abcdefg", ".", 5)   = "abcd."
	    StringUtils.abbreviate("abcdefg", ".", 7)   = "abcdefg"
	    StringUtils.abbreviate("abcdefg", ".", 8)   = "abcdefg"
	    StringUtils.abbreviate("abcdefg", "..", 4)  = "ab.."
	    StringUtils.abbreviate("abcdefg", "..", 3)  = "a.."
	    StringUtils.abbreviate("abcdefg", "..", 2)  = IllegalArgumentException
	    StringUtils.abbreviate("abcdefg", "...", 3) = IllegalArgumentException

4. Abbreviate Middle (String str, String abbrev Marker, int maxWidth) shortens the string to a specified length, and the middle part of the string is displayed as a replacement string (middle).

   Eg:
       StringUtils.abbreviateMiddle("abc", null, 0)      = "abc"
	    StringUtils.abbreviateMiddle("abc", ".", 0)      = "abc"
	    StringUtils.abbreviateMiddle("abc", ".", 3)      = "abc"
	    StringUtils.abbreviateMiddle("abcdef", ".", 4)     = "ab.f"

5. Appendix IfMissing (String str, CharSequence suffix, CharSequence... suffixes) if STR does not end with any suffixes, splice the string suffixes after the string str

Eg:
    StringUtils.appendIfMissing(null, null) = null
    StringUtils.appendIfMissing("abc", null) = "abc"
    StringUtils.appendIfMissing("", "xyz") = "xyz"
    StringUtils.appendIfMissing("abc", "xyz") = "abcxyz"
    StringUtils.appendIfMissing("abcxyz", "xyz") = "abcxyz"
    StringUtils.appendIfMissing("abcXYZ", "xyz") = "abcXYZxyz"

6. Appendix IfMissing Ignore Case (String str, CharSequence suffix, CharSequence... Suffixes are case-insensitive
7.capitalize(String str) capitalizes the first character of the string and returns it
8.center(String str, int size) fills the string STR with space characters so that the string STR is in the middle of a large string of size

Eg:
StringUtils.center(null, *)   = null
StringUtils.center("", 4)     = "    "
StringUtils.center("ab", -1)  = "ab"
StringUtils.center("ab", 4)   = " ab "
StringUtils.center("abcd", 2) = "abcd"
StringUtils.center("a", 4)    = " a  "

9.center(String str, int size, char padChar) fills the string STR in the middle of a large string of size length with specified characters

10.chomp(String str) deletes a newline at the end of the string and returns a new string (newline characters "n", "r", "or"rn").

     Eg:
          StringUtils.chomp(null)          = null
		    StringUtils.chomp("")            = ""
		    StringUtils.chomp("abc \r")      = "abc "
		    StringUtils.chomp("abc\n")       = "abc"
		    StringUtils.chomp("abc\r\n")     = "abc"
		    StringUtils.chomp("abc\r\n\r\n") = "abc\r\n"
		    StringUtils.chomp("abc\n\r")     = "abc\n"
		    StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc"
		    StringUtils.chomp("\r")          = ""
		    StringUtils.chomp("\n")          = ""
		    StringUtils.chomp("\r\n")        = ""

11.chop(String str) deletes a character at the end of a string and returns a new string

     Eg:
		     StringUtils.chop(null)          = null
		    StringUtils.chop("")            = ""
		    StringUtils.chop("abc \r")      = "abc "
		    StringUtils.chop("abc\n")       = "abc"
		    StringUtils.chop("abc\r\n")     = "abc"
		    StringUtils.chop("abc")         = "ab"
		    StringUtils.chop("abc\nabc")    = "abc\nab"
		    StringUtils.chop("a")           = ""
		    StringUtils.chop("\r")          = ""
		    StringUtils.chop("\n")          = ""
		    StringUtils.chop("\r\n")        = ""

12.compare(String str1, String str2) compares two strings and returns an int value

Eg:
      str1 Be equal to str2(Either empty) returns 0
    str1 less than str2 Return less than 0
    str1 greater than str2 Return greater than 0
    StringUtils.compare(null, null)   = 0
    StringUtils.compare(null , "a")   < 0
    StringUtils.compare("a", null)    > 0
    StringUtils.compare("abc", "abc") = 0
    StringUtils.compare("a", "b")     < 0
    StringUtils.compare("b", "a")     > 0
    StringUtils.compare("a", "B")     > 0
    StringUtils.compare("ab", "abc")  < 0

13. contains (CharSequence seq, CharSequence search Seq) checks whether the string contains the specified character and returns boolean

Eg:
    StringUtils.contains(null, *)     = false
    StringUtils.contains(*, null)     = false
    StringUtils.contains("", "")      = true
    StringUtils.contains("abc", "")   = true
    StringUtils.contains("abc", "a")  = true
    StringUtils.contains("abc", "z")  = false

14.containsAny(CharSequence cs, CharSequence... searchCharSequences) Checks whether a string contains any character and returns boolean

Eg:
       StringUtils.containsAny(null, *)            = false
	    StringUtils.containsAny("", *)              = false
	    StringUtils.containsAny(*, null)            = false
	    StringUtils.containsAny(*, [])              = false
	    StringUtils.containsAny("abcd", "ab", null) = true
	    StringUtils.containsAny("abcd", "ab", "cd") = true
	    StringUtils.containsAny("abc", "d", "abc")  = true

15. ContainsNone (CharSequences, String invalidChars) checks that the string does not contain the specified character and returns boolean

	   Eg:
	       StringUtils.containsNone(null, *)       = true
		    StringUtils.containsNone(*, null)       = true
		    StringUtils.containsNone("", *)         = true
		    StringUtils.containsNone("ab", "")      = true
		    StringUtils.containsNone("abab", "xyz") = true
		    StringUtils.containsNone("ab1", "xyz")  = true
		    StringUtils.containsNone("abz", "xyz")  = false

16. ContainsOnly (CharSequences, String validChars) checks that the string contains only specific characters and returns boolean

      Eg:
           StringUtils.containsOnly(null, *)       = false
		    StringUtils.containsOnly(*, null)       = false
		    StringUtils.containsOnly("", *)         = true
		    StringUtils.containsOnly("ab", "")      = false
		    StringUtils.containsOnly("abab", "abc") = true
		    StringUtils.containsOnly("ab1", "abc")  = false
		    StringUtils.containsOnly("abz", "abc")  = false

17.containsWhitespace(CharSequence seq) checks whether the string contains space characters and returns boolean

18.countMatches(CharSequence str, CharSequence sub) checks the number of times a specified character appears in a string and returns an int value

    Eg:
	    StringUtils.countMatches(null, *)       = 0
	    StringUtils.countMatches("", *)         = 0
	    StringUtils.countMatches("abba", null)  = 0
	    StringUtils.countMatches("abba", "")    = 0
	    StringUtils.countMatches("abba", "a")   = 2
	    StringUtils.countMatches("abba", "ab")  = 1
	    StringUtils.countMatches("abba", "xxx") = 0    

19.defaultIfBlank(T str, T defaultStr) returns the specified string if the string is null, empty ("), or full of spaces, otherwise returns the original value.

  Eg: 
	    StringUtils.defaultIfBlank(null, "NULL")  = "NULL"
	    StringUtils.defaultIfBlank("", "NULL")    = "NULL"
	    StringUtils.defaultIfBlank(" ", "NULL")   = "NULL"
	    StringUtils.defaultIfBlank("bat", "NULL") = "bat"
	    StringUtils.defaultIfBlank("", null)      = null

20.defaultIfEmpty(T str, T defaultStr) returns the specified string if the string is null and empty (""), otherwise the original value is returned.

	Eg: 
	    StringUtils.defaultIfEmpty(null, "NULL")  = "NULL"
	    StringUtils.defaultIfEmpty("", "NULL")    = "NULL"
	    StringUtils.defaultIfEmpty(" ", "NULL")   = " "
	    StringUtils.defaultIfEmpty("bat", "NULL") = "bat"
	    StringUtils.defaultIfEmpty("", null)      = null

21.defaultString(String str) If the string is null, it will return an empty string ("), otherwise it will return the original value.

Eg:
    StringUtils.defaultString(null)  = ""
    StringUtils.defaultString("")    = ""
    StringUtils.defaultString("bat") = "bat"

22.defaultString(String str, String defaultStr) returns the specified character if the string is null, otherwise returns the original value.

Eg: 
    	 StringUtils.defaultString(null, "NULL")  = "NULL"
	    StringUtils.defaultString("", "NULL")    = ""
	    StringUtils.defaultString("bat", "NULL") = "bat"

23.deleteWhitespace(String str) deletes the space character in the string and returns a new string

Eg:
	     StringUtils.deleteWhitespace(null)         = null
	    StringUtils.deleteWhitespace("")           = ""
	    StringUtils.deleteWhitespace("abc")        = "abc"
	    StringUtils.deleteWhitespace("   ab  c  ") = "abc"

24.difference(String str1, String str2) compares the difference between two strings, returns the difference character, and returns the remainder of the second string, which means that the difference between "ABC" and "AB" is an empty string rather than "C".

     Eg:
          StringUtils.difference(null, null) = null
		    StringUtils.difference("", "") = ""
		    StringUtils.difference("", "abc") = "abc"
		    StringUtils.difference("abc", "") = ""
		    StringUtils.difference("abc", "abc") = ""
		    StringUtils.difference("abc", "ab") = ""
		    StringUtils.difference("ab", "abxyz") = "xyz"
		    StringUtils.difference("abcde", "abxyz") = "xyz"
		    StringUtils.difference("abcde", "xyz") = "xyz"

25.endsWith(CharSequence str, CharSequence suffix) checks whether a string ends with a specified character and returns a boolean

     Eg:
            StringUtils.endsWith(null, null)      = true
		    StringUtils.endsWith(null, "def")     = false
		    StringUtils.endsWith("abcdef", null)  = false
		    StringUtils.endsWith("abcdef", "def") = true
		    StringUtils.endsWith("ABCDEF", "def") = false
		    StringUtils.endsWith("ABCDEF", "cde") = false
		    StringUtils.endsWith("ABCDEF", "")    = true

26. Ends WithAny (CharSequence sequence, CharSequence... searchStrings) Checks whether the string ends with a specified character array and returns a boolean

      Eg:
            StringUtils.endsWithAny(null, null)      = false
		    StringUtils.endsWithAny(null, new String[] {"abc"})  = false
		    StringUtils.endsWithAny("abcxyz", null)     = false
		    StringUtils.endsWithAny("abcxyz", new String[] {""}) = true
		    StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true
		    StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
		    StringUtils.endsWithAny("abcXYZ", "def", "XYZ") = true
		    StringUtils.endsWithAny("abcXYZ", "def", "xyz") = false

27. Ends WithIgnoreCase (CharSequence str, CharSequence suffix) checks whether a string ends with a specified character (case-insensitive) and returns a boolean

 Eg:
       StringUtils.endsWithIgnoreCase(null, null)      = true
	    StringUtils.endsWithIgnoreCase(null, "def")     = false
	    StringUtils.endsWithIgnoreCase("abcdef", null)  = false
	    StringUtils.endsWithIgnoreCase("abcdef", "def") = true
	    StringUtils.endsWithIgnoreCase("ABCDEF", "def") = true
	    StringUtils.endsWithIgnoreCase("ABCDEF", "cde") = false

28.equals(CharSequence cs1, CharSequence cs2) compares whether two strings are equal, and returns a boolean

 Eg:
       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

29. Equals AnyIgnore Case (CharSequence string, CharSequence... searchStrings) Returns a boolean by comparing whether two strings are equal (case-insensitive)

   Eg:
	    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

30. equals Any (CharSequence string, CharSequence... searchStrings) Returns a boolean by comparing whether a string is equal to a value in the specified string array

  Eg:
        StringUtils.equalsAny(null, (CharSequence[]) null) = false
	    StringUtils.equalsAny(null, null, null)    = true
	    StringUtils.equalsAny(null, "abc", "def")  = false
	    StringUtils.equalsAny("abc", null, "def")  = false
	    StringUtils.equalsAny("abc", "abc", "def") = true
	    StringUtils.equalsAny("abc", "ABC", "DEF") = false

31.getCommonPrefix(String... strs) Gets the common character of the string array element and returns string

    Eg:
            StringUtils.getCommonPrefix(null) = ""
		    StringUtils.getCommonPrefix(new String[] {}) = ""
		    StringUtils.getCommonPrefix(new String[] {"abc"}) = "abc"
		    StringUtils.getCommonPrefix(new String[] {null, null}) = ""
		    StringUtils.getCommonPrefix(new String[] {"", ""}) = ""
		    StringUtils.getCommonPrefix(new String[] {"", null}) = ""
		    StringUtils.getCommonPrefix(new String[] {"abc", null, null}) = ""
		    StringUtils.getCommonPrefix(new String[] {null, null, "abc"}) = ""
		    StringUtils.getCommonPrefix(new String[] {"", "abc"}) = ""
		    StringUtils.getCommonPrefix(new String[] {"abc", ""}) = ""
		    StringUtils.getCommonPrefix(new String[] {"abc", "abc"}) = "abc"
		    StringUtils.getCommonPrefix(new String[] {"abc", "a"}) = "a"
		    StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}) = "ab"
		    StringUtils.getCommonPrefix(new String[] {"abcde", "abxyz"}) = "ab"
		    StringUtils.getCommonPrefix(new String[] {"abcde", "xyz"}) = ""
		    StringUtils.getCommonPrefix(new String[] {"xyz", "abcde"}) = ""
		    StringUtils.getCommonPrefix(new String[] {"i am a machine", "i am a robot"}) = "i am a "

32. indexOf (CharSequence seq, CharSequence search Seq) checks the position of the specified character in the string and returns an int value

Eg:
       StringUtils.indexOf(null, *)          = -1
	    StringUtils.indexOf(*, null)          = -1
	    StringUtils.indexOf("", "")           = 0
	    StringUtils.indexOf("", *)            = -1 (except when * = "")
	    StringUtils.indexOf("aabaabaa", "a")  = 0
	    StringUtils.indexOf("aabaabaa", "b")  = 2
	    StringUtils.indexOf("aabaabaa", "ab") = 1
	    StringUtils.indexOf("aabaabaa", "")   = 0

33. IndexOfIgnoreCase (CharSequence seq, CharSequence search Seq) checks the position of the specified character in the string (case-insensitive) and returns an int value.
34. is All Blank (Char Sequence... css) Checks whether all characters in the array are null, empty, or all space characters, and returns a boolean

Eg :
    StringUtils.isAllBlank(null)             = true
    StringUtils.isAllBlank(null, "foo")      = false
    StringUtils.isAllBlank(null, null)       = true
    StringUtils.isAllBlank("", "bar")        = false
    StringUtils.isAllBlank("bob", "")        = false
    StringUtils.isAllBlank("  bob  ", null)  = false
    StringUtils.isAllBlank(" ", "bar")       = false
    StringUtils.isAllBlank("foo", "bar")     = false
    StringUtils.isAllBlank(new String[] {})  = true

35. is AllEmpty (Char Sequence... css) checks whether all characters in the array are null, empty, and returns a boolean

    Eg:
            StringUtils.isAllEmpty(null)             = true
		    StringUtils.isAllEmpty(null, "")         = true
		    StringUtils.isAllEmpty(new String[] {})  = true
		    StringUtils.isAllEmpty(null, "foo")      = false
		    StringUtils.isAllEmpty("", "bar")        = false
		    StringUtils.isAllEmpty("bob", "")        = false
		    StringUtils.isAllEmpty("  bob  ", null)  = false
		    StringUtils.isAllEmpty(" ", "bar")       = false
		    StringUtils.isAllEmpty("foo", "bar")     = false

36. isAllLowerCase (CharSequences) checks whether all characters in the string are lowercase and returns a boolean

37. isAllUpperCase (CharSequences) checks whether all characters in the string are capitalized and returns a boolean

38. is Any Blank (Char Sequence... css) Check whether a string in the array is null, empty, or full of space characters, and return a boolean

      Eg:
		     StringUtils.isAnyBlank(null)             = true
		    StringUtils.isAnyBlank(null, "foo")      = true
		    StringUtils.isAnyBlank(null, null)       = true
		    StringUtils.isAnyBlank("", "bar")        = true
		    StringUtils.isAnyBlank("bob", "")        = true
		    StringUtils.isAnyBlank("  bob  ", null)  = true
		    StringUtils.isAnyBlank(" ", "bar")       = true
		    StringUtils.isAnyBlank(new String[] {})  = false
		    StringUtils.isAnyBlank(new String[]{""}) = true
		    StringUtils.isAnyBlank("foo", "bar")     = false

39. is AnyEmpty (CharSequence... css) Check whether there is a null, empty string in the array, and return a boolean

   Eg:
		      StringUtils.isAnyEmpty(null)             = true
		    StringUtils.isAnyEmpty(null, "foo")      = true
		    StringUtils.isAnyEmpty("", "bar")        = true
		    StringUtils.isAnyEmpty("bob", "")        = true
		    StringUtils.isAnyEmpty("  bob  ", null)  = true
		    StringUtils.isAnyEmpty(" ", "bar")       = false
		    StringUtils.isAnyEmpty("foo", "bar")     = false
		    StringUtils.isAnyEmpty(new String[]{})   = false
		    StringUtils.isAnyEmpty(new String[]{""}) = true

40.isBlank(CharSequence cs) checks whether the string is null, empty, or space character and returns a boolean

Eg:
       StringUtils.isBlank(null)      = true
	    StringUtils.isBlank("")        = true
	    StringUtils.isBlank(" ")       = true
	    StringUtils.isBlank("bob")     = false
	    StringUtils.isBlank("  bob  ") = false

41.isEmpty(CharSequence cs) checks whether the string is null, empty, and returns a boolean

    Eg: 
		     StringUtils.isEmpty(null)      = true
		    StringUtils.isEmpty("")        = true
		    StringUtils.isEmpty(" ")       = false
		    StringUtils.isEmpty("bob")     = false
		    StringUtils.isEmpty("  bob  ") = false

42.isNotBlank(CharSequence cs) checks whether the string is not null, empty or space character and returns a boolean

43.isNotEmpty(CharSequence cs) checks whether the string is null, empty and returns a boolean

44.isNumeric(CharSequence cs) checks whether the string is a number and returns a boolean

     Eg:
		     StringUtils.isNumeric(null)   = false
		    StringUtils.isNumeric("")     = false
		    StringUtils.isNumeric("  ")   = false
		    StringUtils.isNumeric("123")  = true
		    StringUtils.isNumeric("12 3") = false
		    StringUtils.isNumeric("ab2c") = false
		    StringUtils.isNumeric("12-3") = false
		    StringUtils.isNumeric("12.3") = false
		    StringUtils.isNumeric("-123") = false
		    StringUtils.isNumeric("+123") = false

45. isWhitespace (CharSequences) checks whether the string is a space character and returns a boolean

	    Eg:
			    StringUtils.isWhitespace(null)   = false
			    StringUtils.isWhitespace("")     = true
			    StringUtils.isWhitespace("  ")   = true
			    StringUtils.isWhitespace("abc")  = false
			    StringUtils.isWhitespace("ab2c") = false
			    StringUtils.isWhitespace("ab-c") = false

46.join(byte[] array, char separator) converts byte arrays into string s to specify character separation

Eg:
	    StringUtils.join(null, *)  = null
	    StringUtils.join([], *) = ""
	    StringUtils.join([null], *)= ""
	    StringUtils.join([1, 2, 3], ';') = "1;2;3"
	    StringUtils.join([1, 2, 3], null) = "123"
	    char,double,float,int,long,short,object,T Empathy

47. Join With (String separator, Object... objects) Split and stitch multiple elements with specified characters into String

 Eg: 
	     StringUtils.joinWith(",", {"a", "b"})        = "a,b"
	    StringUtils.joinWith(",", {"a", "b",""})     = "a,b,"
	    StringUtils.joinWith(",", {"a", null, "b"})  = "a,,b"
	    StringUtils.joinWith(null, {"a", "b"})       = "ab"

48. lastIndexOf (CharSequence seq, CharSequence search Seq) Gets the last indexed position of the specified character in the string

    Eg:
       StringUtils.lastIndexOf(null, *)          = -1
	    StringUtils.lastIndexOf(*, null)          = -1
	    StringUtils.lastIndexOf("", "")           = 0
	    StringUtils.lastIndexOf("aabaabaa", "a")  = 7
	    StringUtils.lastIndexOf("aabaabaa", "b")  = 5
	    StringUtils.lastIndexOf("aabaabaa", "ab") = 4
	    StringUtils.lastIndexOf("aabaabaa", "")   = 8

49.left(String str, int len) returns a string of specified size from the left

   Eg:
	    StringUtils.left(null, *)    = null
	    StringUtils.left(*, -ve)     = ""
	    StringUtils.left("", *)      = ""
	    StringUtils.left("abc", 0)   = ""
	    StringUtils.left("abc", 2)   = "ab"
	    StringUtils.left("abc", 4)   = "abc"

50.right(String str, int len) is the opposite

51.length(CharSequence cs) gets the string size and returns an int

52.lowerCase(String str) converts a string to lowercase and returns a string

  Eg:
       StringUtils.lowerCase(null)  = null
	    StringUtils.lowerCase("")    = ""
	    StringUtils.lowerCase("aBc") = "abc"

53. upperCase (String str) is the opposite
53.mid(String str, int pos, int len) retrieves the character of the specified position interval of the string and returns a string

Eg:
	    StringUtils.mid(null, *, *)    = null
	    StringUtils.mid(*, *, -ve)     = ""
	    StringUtils.mid("", 0, *)      = ""
	    StringUtils.mid("abc", 0, 2)   = "ab"
	    StringUtils.mid("abc", 0, 4)   = "abc"
	    StringUtils.mid("abc", 2, 4)   = "c"
	    StringUtils.mid("abc", 4, 2)   = ""
	    StringUtils.mid("abc", -2, 2)  = "ab"

54. Overay (String str, String overlay, int start, int end) inserts a specified character in the string position interval and returns a string.

   Eg: 
        StringUtils.overlay(null, *, *, *)            = null
	    StringUtils.overlay("", "abc", 0, 0)          = "abc"
	    StringUtils.overlay("abcdef", null, 2, 4)     = "abef"
	    StringUtils.overlay("abcdef", "", 2, 4)       = "abef"
	    StringUtils.overlay("abcdef", "", 4, 2)       = "abef"
	    StringUtils.overlay("abcdef", "zzzz", 2, 4)   = "abzzzzef"
	    StringUtils.overlay("abcdef", "zzzz", 4, 2)   = "abzzzzef"
	    StringUtils.overlay("abcdef", "zzzz", -1, 4)  = "zzzzef"
	    StringUtils.overlay("abcdef", "zzzz", 2, 8)   = "abzzzz"
	    StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef"
	    StringUtils.overlay("abcdef", "zzzz", 8, 10)  = "abcdefzzzz"

55.prependIfMissing(String str, CharSequence prefix, CharSequence... Preixes) Insert the specified character to the left of the string. If it already exists, it will not be inserted and returns a string.

   Eg:
	    StringUtils.prependIfMissing(null, null) = null
	    StringUtils.prependIfMissing("abc", null) = "abc"
	    StringUtils.prependIfMissing("", "xyz") = "xyz"
	    StringUtils.prependIfMissing("abc", "xyz") = "xyzabc"
	    StringUtils.prependIfMissing("xyzabc", "xyz") = "xyzabc"
	    StringUtils.prependIfMissing("XYZabc", "xyz") = "xyzXYZabc"

56. Prepend IfMissing Ignore Case (String str, CharSequence prefix, CharSequence... prefixes) Ibid., but case-insensitive

57.remove(String str, char remove) Deletes the specified character in the string and returns a string

Eg:
	    StringUtils.remove(null, *)       = null
	    StringUtils.remove("", *)         = ""
	    StringUtils.remove("queued", 'u') = "qeed"
	    StringUtils.remove("queued", 'z') = "queued"

58.removeIgnoreCase(String str, String remove) is the same, but case-insensitive

59.removeAll(String text, String regex) deletes all characters according to matching rules and returns a string

     Eg: 
         StringUtils.removeAll(null, *)      = null
	    StringUtils.removeAll("any", null)  = "any"
	    StringUtils.removeAll("any", "")    = "any"
	    StringUtils.removeAll("any", ".*")  = ""
	    StringUtils.removeAll("any", ".+")  = ""
	    StringUtils.removeAll("abc", ".?")  = ""
	    StringUtils.removeAll("A<__>\n<__>B", "<.*>")      = "A\nB"
	    StringUtils.removeAll("A<__>\n<__>B", "(?s)<.*>")  = "AB"
	    StringUtils.removeAll("ABCabc123abc", "[a-z]")     = "ABC123"

60.removeEnd(String str, String remove) deletes the specified character at the end of the string and returns a string
61.removeEndIgnoreCase(String str, String remove) is the same, but case-insensitive
62.removeFirst(String text, String regex) deletes the first character according to the matching rule and returns a string.

    Eg: 
       StringUtils.removeFirst(null, *)      = null
	    StringUtils.removeFirst("any", null)  = "any"
	    StringUtils.removeFirst("any", "")    = "any"
	    StringUtils.removeFirst("any", ".*")  = ""
	    StringUtils.removeFirst("any", ".+")  = ""
	    StringUtils.removeFirst("abc", ".?")  = "bc"
	    StringUtils.removeFirst("A<__>\n<__>B", "<.*>")      = "A\n<__>B"
	    StringUtils.removeFirst("A<__>\n<__>B", "(?s)<.*>")  = "AB"
	    StringUtils.removeFirst("ABCabc123", "[a-z]")          = "ABCbc123"
	    StringUtils.removeFirst("ABCabc123abc", "[a-z]+")      = "ABC123abc"

63.repeat(String str, int repeat) splices the specified number of character repetitions into a new string and returns a string

Eg: 
      StringUtils.repeat(null, 2) = null
	    StringUtils.repeat("", 0)   = ""
	    StringUtils.repeat("", 2)   = ""
	    StringUtils.repeat("a", 3)  = "aaa"
	    StringUtils.repeat("ab", 2) = "abab"
	    StringUtils.repeat("a", -2) = ""

64. Replace (String text, String search String, String replacement) replaces all search String in the string with replacement, returning a string

Eg:
        StringUtils.replace(null, *, *)        = null
	    StringUtils.replace("", *, *)          = ""
	    StringUtils.replace("any", null, *)    = "any"
	    StringUtils.replace("any", *, null)    = "any"
	    StringUtils.replace("any", "", *)      = "any"
	    StringUtils.replace("aba", "a", null)  = "aba"
	    StringUtils.replace("aba", "a", "")    = "b"
	    StringUtils.replace("aba", "a", "z")   = "zbz"

65.reverse(String str) reverses the string and returns a string

Eg:
    StringUtils.reverse(null)  = null
    StringUtils.reverse("")    = ""
    StringUtils.reverse("bat") = "tab"

66. Reverse Delimited (String str, char separator Char) reverses the characters specified by the string delimiter

Eg:
	     StringUtils.reverseDelimited(null, *)      = null
	     StringUtils.reverseDelimited("", *)        = ""
	     StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c"
	     StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a"

67. split (String str, String separator Chars) returns an array by separating strings with specified characters

    Eg:
          StringUtils.split(null, *)         = null
		    StringUtils.split("", *)           = []
		    StringUtils.split("abc def", null) = ["abc", "def"]
		    StringUtils.split("abc def", " ")  = ["abc", "def"]
		    StringUtils.split("abc  def", " ") = ["abc", "def"]
		    StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]

68.substring(String str, int start) intercepts a string from a specified position interval and returns a string
69.swapCase(String str) reverses the case of a string and returns a string

Eg: 
	    StringUtils.swapCase(null)                 = null
	    StringUtils.swapCase("")                   = ""
	    StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"

70.toEncodedString(byte[] bytes, Charset charset) converts a string to a specified encoding format and returns a string
71.trim(String str) removes string spaces
72.trimToEmpty(String str) removes string spaces, null turns to empty, and returns a string

Eg:
	     StringUtils.trimToEmpty(null)          = ""
	    StringUtils.trimToEmpty("")            = ""
	    StringUtils.trimToEmpty("     ")       = ""
	    StringUtils.trimToEmpty("abc")         = "abc"
	    StringUtils.trimToEmpty("    abc    ") = "abc"

Topics: Java Apache less Linux