These string utilities provide both convenience methods and performance improvements over most standard library versions. The main aim of the optimizations is to avoid object creation unless absolutely required.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static enum |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | |
| public static final String | |
| private static final char[] | |
| private static final char[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static void | append(StringBuilder
StringBuilder to append to buf, String String to append from s, int The offset of the substring offset, int The length of the substring length)Append substring to StringBuilder |
| public static void | append(StringBuilder
the buffer to append to buf, byte the byte to append b, int the base of the hex output (almost always 16). base)append hex digit |
| public static void | append2digits(StringBuilder
the buffer to append to buf, int the value to append i)Append 2 digits (zero padded) to the StringBuilder |
| public static String[] | Returns: An array of parsed values.The string to parse, expected to be enclosed as '[...]' s)Parse the string representation of a list using |
| public static boolean | Returns: true if the string ends with the substring, ignoringStandardCharsets#US_ASCII case differences.The string to check string, String The sub string to look for as a suffix suffix)Check for a string suffix, ignoring |
| public static boolean | Returns: true if the strings are equal, ignoringStandardCharsets#US_ASCII case differences.The string to check string, String The other string to check other)Check for string equality, ignoring |
| public static boolean | Returns: true if the string ends with the substring, ignoringStandardCharsets#US_ASCII case differences.The string to check string, String The sub string to look for as a prefix prefix)Check for a string prefix, ignoring |
| public static char | Returns: a lower case version of cthe char to convert c)fast lower case conversion. |
| public static byte | Returns: a lower case version of cthe byte to convert c)fast lower case conversion. |
| public static String | Returns: a lower case version of sthe string to convert s)fast lower case conversion. |
| public static String | Returns: a lower case version of sthe string to convert s)fast upper case conversion. |
| public static String[] | Returns: An array of parsed values.The string to parse s)Parse a CSV string using |
| public static String[] | Returns: An array of parsed values.The string to parse s, int The offset into the string to start parsing off, int The len in characters to parse len)Parse a CSV string using |
| public static List | Returns: list containing the parsed list valuesThe Collection to split to (or null to get a new list) list, String The string to parse s, int The offset into the string to start parsing off, int The len in characters to parse len)Split a quoted comma separated string to a list Handle rfc4180-like CSV strings, with the exceptions:
|
| public static boolean | Returns: true if the string ends with the substring, ignoringStandardCharsets#US_ASCII case differences.The string to check string, String The sub string to look for as a suffix suffix)
Deprecated
Use
Check for a string suffix, ignoring asciiEndsWithIgnoreCase(String, String)
StandardCharsets#US_ASCII case differences.
|
| public static boolean | |
| public static byte[] | |
| public static byte[] | |
| public static byte[] | |
| public static int | |
| public static byte[] | |
| public static int | |
| public static int | Returns: the index of first control character in string, -1 if no control characters encounteredthe string to test. str)Find the index of a control characters in String This will return a result on the first occurrence of a control character, regardless if there are more than one. |
| public static boolean | |
| public static boolean | |
| public static boolean | |
| public static boolean | Returns: true if string is not null and has at least 1 non-whitespace character, false if null or all-whitespace characters.the string to test. str)Test if a string is not null and contains at least 1 non-whitespace characters in it. |
| public static String | |
| public static String | |
| public static String | |
| public static String | |
| public static String | |
| public static String | |
| public static String | Returns: the replaced stringthe original string original, String the target string to look for target, String the replacement string to use replacement)Replace first substrings within string. |
| public static String | Returns: the sanitized output string. or null ifstr is null.the raw input string str)Replace all characters from input string that are known to have special meaning in various filesystems. |
| public static String | |
| public static boolean | Returns: true if the string ends with the substring, ignoringStandardCharsets#US_ASCII case differences.The string to check string, String The sub string to look for as a prefix prefix)
Deprecated
Use
Check for a string prefix, ignoring asciiEndsWithIgnoreCase(String, String)
StandardCharsets#US_ASCII case differences.
|
| public static String | |
| public static String | |
| public static String | |
| public static String | |
| public static int | |
| public static String | toString(byte[] b, int offset, int length, String charset)
Deprecated
for removal since 10. use
String#String(byte[], int, int, Charset) instead
|
| public static String | |
| public static String | |
| public static String | Returns: String value or nullThe object object)The String value of an Object This method calls |
| CRLF | back to summary |
|---|---|
| public static final String CRLF | |
| DEFAULT_DELIMS | back to summary |
|---|---|
| public static final String DEFAULT_DELIMS | |
| LOWERCASES | back to summary |
|---|---|
| private static final char[] LOWERCASES | |
| UPPERCASES | back to summary |
|---|---|
| private static final char[] UPPERCASES | |
| StringUtil | back to summary |
|---|---|
| private StringUtil() | |
| append | back to summary |
|---|---|
| public static void append(StringBuilder buf, String s, int offset, int length) Append substring to StringBuilder
| |
| append | back to summary |
|---|---|
| public static void append(StringBuilder buf, byte b, int base) append hex digit
| |
| append2digits | back to summary |
|---|---|
| public static void append2digits(StringBuilder buf, int i) Append 2 digits (zero padded) to the StringBuilder
| |
| arrayFromString | back to summary |
|---|---|
| public static String[] arrayFromString(String s) Parse the string representation of a list using | |
| asciiEndsWithIgnoreCase | back to summary |
|---|---|
| public static boolean asciiEndsWithIgnoreCase(String string, String suffix) Check for a string suffix, ignoring
| |
| asciiEqualsIgnoreCase | back to summary |
|---|---|
| public static boolean asciiEqualsIgnoreCase(String string, String other) Check for string equality, ignoring
| |
| asciiStartsWithIgnoreCase | back to summary |
|---|---|
| public static boolean asciiStartsWithIgnoreCase(String string, String prefix) Check for a string prefix, ignoring
| |
| asciiToLowerCase | back to summary |
|---|---|
| public static char asciiToLowerCase(char c) fast lower case conversion. Only works on ascii (not unicode)
| |
| asciiToLowerCase | back to summary |
|---|---|
| public static byte asciiToLowerCase(byte c) fast lower case conversion. Only works on ascii (not unicode)
| |
| asciiToLowerCase | back to summary |
|---|---|
| public static String asciiToLowerCase(String s) fast lower case conversion. Only works on ascii (not unicode) | |
| asciiToUpperCase | back to summary |
|---|---|
| public static String asciiToUpperCase(String s) fast upper case conversion. Only works on ascii (not unicode) | |
| csvSplit | back to summary |
|---|---|
| public static String[] csvSplit(String s) Parse a CSV string using | |
| csvSplit | back to summary |
|---|---|
| public static String[] csvSplit(String s, int off, int len) Parse a CSV string using | |
| csvSplit | back to summary |
|---|---|
| public static List Split a quoted comma separated string to a list Handle rfc4180-like CSV strings, with the exceptions:
| |
| endsWithIgnoreCase | back to summary |
|---|---|
| public static boolean endsWithIgnoreCase(String string, String suffix)
Deprecated Check for a string suffix, ignoring
| |
| equals | back to summary |
|---|---|
| public static boolean equals(String s, char[] buf, int offset, int length) | |
| fromHexString | back to summary |
|---|---|
| public static byte[] fromHexString(String s) | |
| getBytes | back to summary |
|---|---|
| public static byte[] getBytes(String s) | |
| getBytes | back to summary |
|---|---|
| public static byte[] getBytes(String s, String charset) | |
| getLength | back to summary |
|---|---|
| public static int getLength(String s) Get the length of a string where a null string is length 0.
| |
| getUtf8Bytes | back to summary |
|---|---|
| public static byte[] getUtf8Bytes(String s) | |
| indexFrom | back to summary |
|---|---|
| public static int indexFrom(String s, String chars) returns the next index of a character from the chars string | |
| indexOfControlChars | back to summary |
|---|---|
| public static int indexOfControlChars(String str) Find the index of a control characters in String This will return a result on the first occurrence of a control character, regardless if there are more than one. Note uses codepoint version of
indexOfControlChars(null) == -1
indexOfControlChars("") == -1
indexOfControlChars("\r\n") == 0
indexOfControlChars("\t") == 0
indexOfControlChars(" ") == -1
indexOfControlChars("a") == -1
indexOfControlChars(".") == -1
indexOfControlChars(";\n") == 1
indexOfControlChars("abc\f") == 3
indexOfControlChars("z\010") == 1
indexOfControlChars(":
") == 1
| |
| isBlank | back to summary |
|---|---|
| public static boolean isBlank(String str) Test if a string is null or only has whitespace characters in it. Note uses codepoint version of
isBlank(null) == true
isBlank("") == true
isBlank("\r\n") == true
isBlank("\t") == true
isBlank(" ") == true
isBlank("a") == false
isBlank(".") == false
isBlank(";\n") == false
| |
| isEmpty | back to summary |
|---|---|
| public static boolean isEmpty(String str) Checks if a String is empty ("") or null.
isEmpty(null) == true
isEmpty("") == true
isEmpty("\r\n") == false
isEmpty("\t") == false
isEmpty(" ") == false
isEmpty("a") == false
isEmpty(".") == false
isEmpty(";\n") == false
| |
| isHex | back to summary |
|---|---|
| public static boolean isHex(String str, int offset, int length) | |
| isNotBlank | back to summary |
|---|---|
| public static boolean isNotBlank(String str) Test if a string is not null and contains at least 1 non-whitespace characters in it. Note uses codepoint version of
isNotBlank(null) == false
isNotBlank("") == false
isNotBlank("\r\n") == false
isNotBlank("\t") == false
isNotBlank(" ") == false
isNotBlank("a") == true
isNotBlank(".") == true
isNotBlank(";\n") == true
| |
| nonNull | back to summary |
|---|---|
| public static String nonNull(String s) Return a non null string. | |
| printable | back to summary |
|---|---|
| public static String printable(String name) | |
| printable | back to summary |
|---|---|
| public static String printable(byte[] b) | |
| randomAlphaNumeric | back to summary |
|---|---|
| public static String randomAlphaNumeric(int digits) | |
| replace | back to summary |
|---|---|
| public static String replace(String str, char find, char with) Replace chars within string.
Fast replacement for | |
| replace | back to summary |
|---|---|
| public static String replace(String s, String sub, String with) Replace substrings within string.
Fast replacement for | |
| replaceFirst | back to summary |
|---|---|
| public static String replaceFirst(String original, String target, String replacement) Replace first substrings within string.
Fast replacement for | |
| sanitizeFileSystemName | back to summary |
|---|---|
| public static String sanitizeFileSystemName(String str) Replace all characters from input string that are known to have special meaning in various filesystems.
This will replace all of the following characters
with a "
| |
| sanitizeXmlString | back to summary |
|---|---|
| public static String sanitizeXmlString(String html) | |
| startsWithIgnoreCase | back to summary |
|---|---|
| public static boolean startsWithIgnoreCase(String string, String prefix)
Deprecated Check for a string prefix, ignoring
| |
| strip | back to summary |
|---|---|
| public static String strip(String str, String find) | |
| toHexString | back to summary |
|---|---|
| public static String toHexString(byte b) | |
| toHexString | back to summary |
|---|---|
| public static String toHexString(byte[] b) | |
| toHexString | back to summary |
|---|---|
| public static String toHexString(byte[] b, int offset, int length) | |
| toInt | back to summary |
|---|---|
| public static int toInt(String string, int from) Convert String to an integer. Parses up to the first non-numeric character. If no number is found an IllegalArgumentException is thrown
| |
| toString | back to summary |
|---|---|
public static String toString(byte[] b, int offset, int length, String charset)
| |
| toUTF8String | back to summary |
|---|---|
| public static String toUTF8String(byte[] b, int offset, int length) | |
| truncate | back to summary |
|---|---|
| public static String truncate(String str, int maxSize) Truncate a string to a max size. | |
| valueOf | back to summary |
|---|---|
| public static String valueOf(Object object) The String value of an Object This method calls | |
| Modifier and Type | Field and Description |
|---|---|
| public static final StringUtil. | |
| public static final StringUtil. | |
| public static final StringUtil. | |
| public static final StringUtil. | |
| public static final StringUtil. | |
| public static final StringUtil. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static StringUtil. | |
| public static StringUtil. |
| DATA | back to summary |
|---|---|
| public static final StringUtil. | |
| POST_DATA | back to summary |
|---|---|
| public static final StringUtil. | |
| PRE_DATA | back to summary |
|---|---|
| public static final StringUtil. | |
| QUOTE | back to summary |
|---|---|
| public static final StringUtil. | |
| SLOSH | back to summary |
|---|---|
| public static final StringUtil. | |
| WHITE | back to summary |
|---|---|
| public static final StringUtil. | |
| CsvSplitState | back to summary |
|---|---|
| private CsvSplitState() | |
| valueOf | back to summary |
|---|---|
| public static StringUtil. | |
| values | back to summary |
|---|---|
| public static StringUtil. | |