| Modifier and Type | Field and Description |
|---|---|
static String |
EMPTY
The empty String
"". |
static int |
INDEX_NOT_FOUND
Represents a failed index search.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
equals(CharSequence cs1,
CharSequence cs2)
Compares two CharSequences, returning
true if they represent equal
sequences of characters. |
static boolean |
isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
|
static boolean |
isEmpty(CharSequence cs)
Checks if a CharSequence is empty ("") or null.
|
static boolean |
isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static boolean |
isNotEmpty(CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
|
static boolean |
regionMatches(CharSequence cs,
boolean ignoreCase,
int thisStart,
CharSequence substring,
int start,
int length)
Green implementation of regionMatches.
|
static String |
substringAfter(String str,
String separator)
Gets the substring after the first occurrence of a separator.
|
static String |
substringBetween(String str,
String tag)
Gets the String that is nested in between two instances of the same String.
|
static String |
substringBetween(String str,
String open,
String close)
Gets the String that is nested in between two Strings.
|
static String |
trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling
null by returning null. |
public static final String EMPTY
"".public static final int INDEX_NOT_FOUND
public static boolean isEmpty(CharSequence cs)
Checks if a CharSequence 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 CharSequence. That functionality is available in isBlank().
cs - the CharSequence to check, may be nulltrue if the CharSequence is empty or nullpublic static boolean isNotEmpty(CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is not empty and not nullpublic static boolean isBlank(CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
cs - the CharSequence to check, may be nulltrue if the CharSequence is null, empty or whitespacepublic static boolean isNotBlank(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
Whitespace is defined by Character.isWhitespace(char).
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is not empty and not null and not
whitespace onlypublic static String trim(String str)
Removes control characters (char <= 32) from both ends of this String, handling
null by returning null.
The String is trimmed using String.trim(). Trim removes start and end
characters <= 32.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
str - the String to be trimmed, may be nullnull if null String inputpublic static boolean equals(CharSequence cs1, CharSequence cs2)
Compares two CharSequences, returning true if they represent equal
sequences of characters.
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
cs1 - the first CharSequence, may be nullcs2 - the second CharSequence, may be nulltrue if the CharSequences are equal (case-sensitive), or both
nullObject.equals(Object)public static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length)
cs - the CharSequence to be processedignoreCase - whether or not to be case insensitivethisStart - the index to start on the cs CharSequencesubstring - the CharSequence to be looked forstart - the index to start on the substring CharSequencelength - character length of the regionpublic static String substringAfter(String str, String separator)
Gets the substring after the first occurrence 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.
If nothing is found, the empty string is returned.
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"
str - the String to get a substring from, may be nullseparator - the String to search for, may be nullnull if null String inputpublic static String substringBetween(String str, String tag)
Gets the String that is nested in between two instances of the same String.
A null input String returns null. A null tag
returns null.
StringUtils.substringBetween(null, *) = null
StringUtils.substringBetween("", "") = ""
StringUtils.substringBetween("", "tag") = null
StringUtils.substringBetween("tagabctag", null) = null
StringUtils.substringBetween("tagabctag", "") = ""
StringUtils.substringBetween("tagabctag", "tag") = "abc"
str - the String containing the substring, may be nulltag - the String before and after the substring, may be nullnull if no matchpublic static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings. Only the first match is returned.
A null input String returns null. A null
open/close returns null (no match). An empty ("") open and close
returns an empty string.
StringUtils.substringBetween("wx[b]yz", "[", "]") = "b"
StringUtils.substringBetween(null, *, *) = null
StringUtils.substringBetween(*, null, *) = null
StringUtils.substringBetween(*, *, null) = null
StringUtils.substringBetween("", "", "") = ""
StringUtils.substringBetween("", "", "]") = null
StringUtils.substringBetween("", "[", "]") = null
StringUtils.substringBetween("yabcz", "", "") = ""
StringUtils.substringBetween("yabcz", "y", "z") = "abc"
StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc"
str - the String containing the substring, may be nullopen - the String before the substring, may be nullclose - the String after the substring, may be nullnull if no matchCopyright © 2021 Pivotal Software, Inc.. All rights reserved.