public abstract class StringUtil extends Object
Note: This class includes codes copied from Apache Commons Lang, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.
| Modifier and Type | Class and Description |
|---|---|
static class |
StringUtil.MoreStringUtil |
static class |
StringUtil.Strings |
| Modifier and Type | Field and Description |
|---|---|
static String |
CR
A String for carriage return CR ("\r").
|
static String |
EMPTY
The empty String
"". |
static String |
LF
A String for linefeed LF ("\n").
|
static String |
SPACE
A String for a space character.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
abbreviate(String str,
int maxWidth)
Abbreviates a String using ellipses.
|
static String |
abbreviate(String str,
String abbrevMarker,
int maxWidth)
Abbreviates a String using another given String as replacement marker.
|
static String |
abbreviateMiddle(String str,
String middle,
int length)
Abbreviates a String to the length passed, replacing the middle characters with the supplied
replacement String.
|
static String |
appendIfMissing(String str,
String suffix)
Append if missing.
|
static String |
appendIfMissingIgnoreCase(String str,
String suffix) |
static String |
capitalize(String str) |
static String |
center(String str,
int size)
Centers a String in a larger String of size
size
using the space character (' '). |
static String |
center(String str,
int size,
char padChar)
Centers a String in a larger String of size
size. |
static String |
center(String str,
int minLength,
String padStr)
Centers a String in a larger String of size
minLength. |
static String |
chomp(String str)
Removes one newline from end of a String if it's there, otherwise leave
it alone.
|
static void |
chomp(String[] strs) |
static String |
chop(String str)
Remove the last character from a String.
|
static void |
chop(String[] strs) |
static String |
commonPrefix(String... strs) |
static String |
commonPrefix(String a,
String b)
Note: copy rights: Google Guava.
|
static String |
commonSuffix(String... strs) |
static String |
commonSuffix(String a,
String b)
Note: copy rights: Google Guava.
|
static String |
concat(Object a,
Object b)
Returns
N.toString(a) + N.toString(b). |
static String |
concat(Object a,
Object b,
Object c) |
static String |
concat(Object a,
Object b,
Object c,
Object d) |
static String |
concat(Object a,
Object b,
Object c,
Object d,
Object e) |
static String |
concat(Object a,
Object b,
Object c,
Object d,
Object e,
Object f) |
static String |
concat(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g)
Returns
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g). |
static String |
concat(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h)
Returns
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g) + N.toString(h). |
static String |
concat(Object a,
Object b,
Object c,
Object d,
Object e,
Object f,
Object g,
Object h,
Object i)
Returns
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g) + N.toString(h) + N.toString(i). |
static String |
concat(String... a) |
static String |
concat(String a,
String b)
Returns
a + b. |
static String |
concat(String a,
String b,
String c) |
static String |
concat(String a,
String b,
String c,
String d) |
static String |
concat(String a,
String b,
String c,
String d,
String e) |
static String |
concat(String a,
String b,
String c,
String d,
String e,
String f) |
static String |
concat(String a,
String b,
String c,
String d,
String e,
String f,
String g) |
static String |
concat(String a,
String b,
String c,
String d,
String e,
String f,
String g,
String h) |
static String |
concat(String a,
String b,
String c,
String d,
String e,
String f,
String g,
String h,
String i) |
static boolean |
contains(String str,
int targetChar) |
static boolean |
contains(String str,
String substr) |
static boolean |
contains(String str,
String substr,
String delimiter) |
static boolean |
containsAny(String str,
char... chs) |
static boolean |
containsIgnoreCase(String str,
String substr)
Contains ignore case.
|
static boolean |
containsNone(String str,
char... chs) |
static boolean |
containsOnly(String str,
char... chs) |
static boolean |
containsWhitespace(String str) |
static int |
countMatches(String str,
char ch) |
static int |
countMatches(String str,
String substr) |
static <T extends CharSequence> |
defaultIfBlank(T str,
Supplier<? extends T> getterForDefaultStr) |
static <T extends CharSequence> |
defaultIfBlank(T str,
T defaultStr)
Same as
N.defaultIfNullOrEmptyOrBlank(CharSequence, CharSequence). |
static <T extends CharSequence> |
defaultIfEmpty(T str,
Supplier<? extends T> getterForDefaultStr) |
static <T extends CharSequence> |
defaultIfEmpty(T str,
T defaultStr)
Same as
N.defaultIfNullOrEmpty(CharSequence, CharSequence). |
static String |
deleteWhitespace(String str)
Deletes all white spaces from a String as defined by
Character.isWhitespace(char). |
static void |
deleteWhitespace(String[] strs) |
static String |
emptyToNull(String str) |
static void |
emptyToNull(String[] strs) |
static boolean |
endsWith(String str,
String suffix) |
static boolean |
endsWithAny(String str,
String... substrs)
Ends with any.
|
static boolean |
endsWithIgnoreCase(String str,
String suffix)
Ends with ignore case.
|
static boolean |
equals(String a,
String b) |
static boolean |
equalsAny(String str,
String... searchStrings)
Equals with any.
|
static boolean |
equalsAnyIgnoreCase(String str,
String... searchStrings)
Equals with any.
|
static boolean |
equalsIgnoreCase(String a,
String b)
Equals ignore case.
|
static u.OptionalChar |
firstChar(String str)
findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]. |
static String |
firstChars(String str,
int n)
Returns the first
n chars of the specified String if its length is bigger than n,
or an empty String "" if str is empty or null, or itself it's length equal to or less than n. |
static <T extends CharSequence> |
firstNonBlank(T... values) |
static <T extends CharSequence> |
firstNonEmpty(T... values)
Returns the first value in the array which is not empty.
|
static int |
indexOf(String str,
int targetChar) |
static int |
indexOf(String str,
int fromIndex,
int targetChar) |
static int |
indexOf(String str,
int fromIndex,
String substr) |
static int |
indexOf(String str,
int fromIndex,
String substr,
String delimiter) |
static int |
indexOf(String str,
String substr) |
static int |
indexOf(String str,
String substr,
String delimiter) |
static int |
indexOfAny(String str,
char... chs)
Index of any.
|
static int |
indexOfAny(String str,
String... substrs)
Index of any.
|
static int |
indexOfAnyBut(String str,
char... chs)
Index of any but.
|
static int |
indexOfDifference(String... strs)
Compares all Strings in an array and returns the index at which the
Strings begin to differ.
|
static int |
indexOfDifference(String a,
String b)
Compares two Strings, and returns the index at which the Stringss begin
to differ.
|
static int |
indexOfIgnoreCase(String str,
int fromIndex,
String substr)
Index of ignore case.
|
static int |
indexOfIgnoreCase(String str,
String substr)
Index of ignore case.
|
static boolean |
isAllBlank(CharSequence... css)
Checks if all of the CharSequences are empty (""), null or whitespace only.
|
static boolean |
isAllEmpty(CharSequence... css)
Checks if all of the CharSequences are empty ("") or null.
|
static boolean |
isAllLowerCase(CharSequence cs)
Checks if is all lower case.
|
static boolean |
isAllUpperCase(CharSequence cs)
Checks if is all upper case.
|
static boolean |
isAlpha(CharSequence cs)
Checks if the CharSequence contains only Unicode letters.
|
static boolean |
isAlphanumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode letters or digits.
|
static boolean |
isAlphanumericSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode letters, digits or space
(
' '). |
static boolean |
isAlphaSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode letters and space (' ').
|
static boolean |
isAnyBlank(CharSequence... css)
Checks if any of the CharSequences are empty ("") or null or whitespace only.
|
static boolean |
isAnyEmpty(CharSequence... css)
Checks if any of the CharSequences are empty ("") or null.
|
static boolean |
isAscii(char ch)
Checks whether the character is ASCII 7 bit.
|
static boolean |
isAsciiAlpha(char ch)
Checks whether the character is ASCII 7 bit alphabetic.
|
static boolean |
isAsciiAlpha(CharSequence cs)
Checks if is ascii alpha.
|
static boolean |
isAsciiAlphaLower(char ch)
Checks whether the character is ASCII 7 bit alphabetic lower case.
|
static boolean |
isAsciiAlphanumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
|
static boolean |
isAsciiAlphanumeric(CharSequence cs)
Checks if is ascii alphanumeric.
|
static boolean |
isAsciiAlphanumericSpace(CharSequence cs)
Checks if is ascii alphanumeric space.
|
static boolean |
isAsciiAlphaSpace(CharSequence cs)
Checks if is ascii alpha space.
|
static boolean |
isAsciiAlphaUpper(char ch)
Checks whether the character is ASCII 7 bit alphabetic upper case.
|
static boolean |
isAsciiControl(char ch)
Checks whether the character is ASCII 7 bit control.
|
static boolean |
isAsciiDigtalInteger(String str)
true is returned if the specified str only
includes characters ('0' ~ '9', '-', '+' ). |
static boolean |
isAsciiDigtalNumber(String str)
true is returned if the specified str only
includes characters ('0' ~ '9', '.', '-', '+', 'e'). |
static boolean |
isAsciiLowerCase(char ch)
Checks if is ascii lower case.
|
static boolean |
isAsciiNumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
|
static boolean |
isAsciiNumeric(CharSequence cs)
Checks if is ascii numeric.
|
static boolean |
isAsciiPrintable(char ch)
Checks whether the character is ASCII 7 bit printable.
|
static boolean |
isAsciiPrintable(CharSequence cs)
Checks if is ascii printable.
|
static boolean |
isAsciiUpperCase(char ch)
Checks if is ascii upper case.
|
static boolean |
isBlank(CharSequence cs)
Same as
N.isNullOrEmptyOrBlank(CharSequence). |
static boolean |
isDigit(char ch)
Checks if is digit.
|
static boolean |
isEmpty(CharSequence cs)
Same as
N.isNullOrEmpty(CharSequence). |
static boolean |
isLetter(char ch)
Checks if is letter.
|
static boolean |
isLetterOrDigit(char ch)
Checks if is letter or digit.
|
static boolean |
isLowerCase(char ch)
Checks if is lower case.
|
static boolean |
isMixedCase(CharSequence cs)
Copied from Apache Commons Lang: StringUtils#isMixedCase.
|
static boolean |
isNotBlank(CharSequence cs)
Same as
N.notNullOrEmptyOrBlank(CharSequence). |
static boolean |
isNotEmpty(CharSequence cs)
Same as
N.notNullOrEmpty(CharSequence). |
static boolean |
isNumber(String str)
Note: It's copied from NumberUtils in Apache Commons Lang under Apache
License 2.0
|
static boolean |
isNumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
|
static boolean |
isNumericSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode digits or space (
' '). |
static boolean |
isUpperCase(char ch)
Checks if is upper case.
|
static boolean |
isWhitespace(CharSequence cs)
Checks if the CharSequence contains only whitespace.
|
static String |
join(boolean[] a) |
static String |
join(boolean[] a,
char delimiter) |
static String |
join(boolean[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(boolean[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(boolean[] a,
String delimiter) |
static String |
join(byte[] a) |
static String |
join(byte[] a,
char delimiter) |
static String |
join(byte[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(byte[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(byte[] a,
String delimiter) |
static String |
join(char[] a) |
static String |
join(char[] a,
char delimiter) |
static String |
join(char[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(char[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(char[] a,
String delimiter) |
static String |
join(Collection<?> c) |
static String |
join(Collection<?> c,
char delimiter) |
static String |
join(Collection<?> c,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(Collection<?> c,
int fromIndex,
int toIndex,
char delimiter,
boolean trim) |
static String |
join(Collection<?> c,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(Collection<?> c,
int fromIndex,
int toIndex,
String delimiter,
boolean trim) |
static String |
join(Collection<?> c,
int fromIndex,
int toIndex,
String delimiter,
String prefix,
String suffix,
boolean trim) |
static String |
join(Collection<?> c,
String delimiter) |
static String |
join(Collection<?> c,
String delimiter,
String prefix,
String suffix) |
static String |
join(Collection<?> c,
String delimiter,
String prefix,
String suffix,
boolean trim) |
static String |
join(double[] a) |
static String |
join(double[] a,
char delimiter) |
static String |
join(double[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(double[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(double[] a,
String delimiter) |
static String |
join(float[] a) |
static String |
join(float[] a,
char delimiter) |
static String |
join(float[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(float[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(float[] a,
String delimiter) |
static String |
join(int[] a) |
static String |
join(int[] a,
char delimiter) |
static String |
join(int[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(int[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(int[] a,
String delimiter) |
static String |
join(Iterator<?> iter) |
static String |
join(Iterator<?> iter,
char delimiter) |
static String |
join(Iterator<?> iter,
String delimiter) |
static String |
join(Iterator<?> iter,
String delimiter,
String prefix,
String suffix,
boolean trim) |
static String |
join(long[] a) |
static String |
join(long[] a,
char delimiter) |
static String |
join(long[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(long[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(long[] a,
String delimiter) |
static String |
join(Object[] a) |
static String |
join(Object[] a,
char delimiter) |
static String |
join(Object[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(Object[] a,
int fromIndex,
int toIndex,
char delimiter,
boolean trim) |
static String |
join(Object[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(Object[] a,
int fromIndex,
int toIndex,
String delimiter,
boolean trim) |
static String |
join(Object[] a,
int fromIndex,
int toIndex,
String delimiter,
String prefix,
String suffix,
boolean trim) |
static String |
join(Object[] a,
String delimiter) |
static String |
join(Object[] a,
String delimiter,
String prefix,
String suffix) |
static String |
join(Object[] a,
String delimiter,
String prefix,
String suffix,
boolean trim) |
static String |
join(short[] a) |
static String |
join(short[] a,
char delimiter) |
static String |
join(short[] a,
int fromIndex,
int toIndex,
char delimiter) |
static String |
join(short[] a,
int fromIndex,
int toIndex,
String delimiter) |
static String |
join(short[] a,
String delimiter) |
static String |
joinEntries(Map<?,?> m) |
static String |
joinEntries(Map<?,?> m,
char entryDelimiter) |
static String |
joinEntries(Map<?,?> m,
char entryDelimiter,
char keyValueDelimiter) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
char entryDelimiter) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
char entryDelimiter,
boolean trim) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
char entryDelimiter,
char keyValueDelimiter) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
char entryDelimiter,
char keyValueDelimiter,
boolean trim) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
String entryDelimiter) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
String entryDelimiter,
boolean trim) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
String entryDelimiter,
String keyValueDelimiter) |
static String |
joinEntries(Map<?,?> m,
int fromIndex,
int toIndex,
String entryDelimiter,
String keyValueDelimiter,
String prefix,
String suffix,
boolean trim) |
static String |
joinEntries(Map<?,?> m,
String entryDelimiter) |
static String |
joinEntries(Map<?,?> m,
String entryDelimiter,
String keyValueDelimiter) |
static String |
joinEntries(Map<?,?> m,
String entryDelimiter,
String keyValueDelimiter,
String prefix,
String suffix) |
static String |
joinEntries(Map<?,?> m,
String entryDelimiter,
String keyValueDelimiter,
String prefix,
String suffix,
boolean trim) |
static u.OptionalChar |
lastChar(String str) |
static String |
lastChars(String str,
int n)
Returns the last
n chars of the specified String if its length is bigger than n,
or an empty String "" if str is empty or null, or itself it's length equal to or less than n. |
static int |
lastIndexOf(String str,
int targetChar)
Last index of.
|
static int |
lastIndexOf(String str,
int fromIndex,
int targetChar)
Returns the index within this string of the last occurrence of the
specified character, searching backward starting at the specified index.
|
static int |
lastIndexOf(String str,
int fromIndex,
String substr)
Returns the index within
str of the last occurrence of the
specified substr, searching backward starting at the
specified index. |
static int |
lastIndexOf(String str,
int fromIndex,
String substr,
String delimiter)
Last index of.
|
static int |
lastIndexOf(String str,
String substr)
Last index of.
|
static int |
lastIndexOf(String str,
String substr,
String delimiter)
Last index of.
|
static int |
lastIndexOfAny(String str,
char... chs)
Last index of any.
|
static int |
lastIndexOfAny(String str,
String... substrs)
Last index of any.
|
static int |
lastIndexOfIgnoreCase(String str,
int fromIndex,
String substr)
Last index of ignore case.
|
static int |
lastIndexOfIgnoreCase(String str,
String substr)
Last index of ignore case.
|
static int |
lastOrdinalIndexOf(String str,
String substr,
int ordinal)
Finds the n-th last index within a String, handling
null. |
static String |
lenientFormat(String template,
Object... args)
Copied from Google Guava
Returns the given template string with each occurrence of "%s" replaced with
the corresponding argument value from args; or, if the placeholder and argument counts
do not match, returns a best-effort form of that string. |
static String |
longestCommonSubstring(String a,
String b) |
static String |
normalizeSpace(String str)
|
static String |
nullToEmpty(String str) |
static void |
nullToEmpty(String[] strs) |
static int |
occurrencesOf(String str,
String substr) |
static int |
ordinalIndexOf(String str,
String substr,
int ordinal)
Finds the n-th index within a String, handling
null. |
static String |
overlay(String str,
String overlay,
int start,
int end)
Overlays part of a String with another String.
|
static String |
padEnd(String str,
int minLength) |
static String |
padEnd(String str,
int minLength,
char padChar) |
static String |
padEnd(String str,
int minLength,
String padStr) |
static String |
padStart(String str,
int minLength) |
static String |
padStart(String str,
int minLength,
char padChar) |
static String |
padStart(String str,
int minLength,
String padStr) |
static String |
prependIfMissing(String str,
String prefix)
Prepend if missing.
|
static String |
prependIfMissingIgnoreCase(String str,
String prefix) |
static String |
quoteEscaped(String str)
Replace ''' or '"' with '\'' or '\"' if the previous char of the
quotation is not '\'.
|
static String |
removeAll(String str,
char removeChar)
Removes all occurrences of a character from within the source string.
|
static String |
removeAll(String str,
int fromIndex,
char removeChar)
Removes the all.
|
static String |
removeAll(String str,
int fromIndex,
String removeStr)
Removes the all.
|
static String |
removeAll(String str,
String removeStr)
Removes all occurrences of a substring from within the source string.
|
static String |
removeEnd(String str,
String removeStr)
Removes a substring only if it is at the end of a source string,
otherwise returns the source string.
|
static String |
removeEndIgnoreCase(String str,
String removeStr)
Case insensitive removal of a substring if it is at the end of a source
string, otherwise returns the source string.
|
static String |
removePattern(String source,
String regex)
Removes each substring of the source String that matches the given
regular expression using the DOTALL option.
|
static String |
removeStart(String str,
String removeStr)
Removes a substring only if it is at the beginning of a source string,
otherwise returns the source string.
|
static String |
removeStartIgnoreCase(String str,
String removeStr)
Case insensitive removal of a substring if it is at the beginning of a
source string, otherwise returns the source string.
|
static String |
repeat(char ch,
int n) |
static String |
repeat(char ch,
int n,
char delimiter) |
static String |
repeat(String str,
int repeat) |
static String |
repeat(String str,
int n,
String delimiter) |
static String |
repeat(String str,
int n,
String delimiter,
String prefix,
String suffix) |
static String |
replace(String str,
int fromIndex,
String target,
String replacement,
int max)
Replaces a String with another String inside a larger String, for the
first
max values of the search String. |
static String |
replaceAll(String str,
int fromIndex,
String target,
String replacement) |
static String |
replaceAll(String str,
String target,
String replacement)
Replaces all occurrences of a String within another String.
|
static String |
replaceAllIgnoreCase(String str,
int fromIndex,
String target,
String replacement)
Replace all ignore case.
|
static String |
replaceAllIgnoreCase(String str,
String target,
String replacement)
Replace all ignore case.
|
static String |
replaceIgnoreCase(String str,
int fromIndex,
String target,
String replacement,
int max)
Replace ignore case.
|
static String |
replaceOnce(String str,
int fromIndex,
String target,
String replacement) |
static String |
replaceOnce(String str,
String target,
String replacement)
Replaces a String with another String inside a larger String, once.
|
static String |
replaceOnceIgnoreCase(String str,
int fromIndex,
String target,
String replacement)
Replace once ignore case.
|
static String |
replaceOnceIgnoreCase(String str,
String target,
String replacement)
Replace once ignore case.
|
static String |
replacePattern(String source,
String regex,
String replacement)
Replaces each substring of the source String that matches the given
regular expression with the given replacement using the
Pattern.DOTALL option. |
static String |
reverse(String str) |
static String |
reverseDelimited(String str,
char delimiter)
Reverses a String that is delimited by a specific character.
|
static String |
reverseDelimited(String str,
String delimiter) |
static String |
rotate(String str,
int shift)
Rotate (circular shift) a String of
shift characters. |
static String |
shuffle(String str) |
static String |
shuffle(String str,
Random rnd) |
static String |
sort(String str)
Returns a new sorted String if the specified
str is not null or empty, otherwise the specified str is returned. |
static String[] |
split(String str,
char delimiter) |
static String[] |
split(String str,
char delimiter,
boolean trim) |
static String[] |
split(String str,
String delimiter) |
static String[] |
split(String str,
String delimiter,
boolean trim) |
static String[] |
split(String str,
String delimiter,
int max)
Deprecated.
Splitter is recommended. |
static String[] |
split(String str,
String delimiter,
int max,
boolean trim)
Deprecated.
Splitter is recommended. |
static String[] |
splitPreserveAllTokens(String str,
char delimiter)
Split preserve all tokens.
|
static String[] |
splitPreserveAllTokens(String str,
char delimiter,
boolean trim)
Split preserve all tokens.
|
static String[] |
splitPreserveAllTokens(String str,
String delimiter)
Split preserve all tokens.
|
static String[] |
splitPreserveAllTokens(String str,
String delimiter,
boolean trim)
Split preserve all tokens.
|
static String[] |
splitPreserveAllTokens(String str,
String delimiter,
int max)
Deprecated.
Splitter is recommended. |
static String[] |
splitPreserveAllTokens(String str,
String delimiter,
int max,
boolean trim)
Deprecated.
Splitter is recommended. |
static boolean |
startsWith(String str,
String prefix) |
static boolean |
startsWithAny(String str,
String... substrs)
Starts with any.
|
static boolean |
startsWithIgnoreCase(String str,
String prefix)
Starts with ignore case.
|
static String |
strip(String str)
Strips whitespace from the start and end of a String.
|
static void |
strip(String[] strs) |
static void |
strip(String[] strs,
String stripChars) |
static String |
strip(String str,
String stripChars)
Strips any of a set of characters from the start and end of a String.
|
static String |
stripAccents(String str)
Removes diacritics (~= accents) from a string.
|
static void |
stripAccents(String[] strs) |
static void |
stripEnd(String[] strs,
String stripChars) |
static String |
stripEnd(String str,
String stripChars)
Strips any of a set of characters from the end of a String.
|
static void |
stripStart(String[] strs,
String stripChars) |
static String |
stripStart(String str,
String stripChars)
Strips any of a set of characters from the start of a String.
|
static String |
stripToEmpty(String str)
Strips whitespace from the start and end of a String returning an empty
String if
null input. |
static void |
stripToEmpty(String[] strs) |
static String |
stripToNull(String str)
Strips whitespace from the start and end of a String returning
null if the String is empty ("") after the strip. |
static void |
stripToNull(String[] strs) |
static String |
substring(String str,
char delimiterOfInclusiveBeginIndex)
Returns
null if N.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0,
otherwise the substring with String value: str.substring(str.indexOf(delimiterOfInclusiveBeginIndex)) is returned. |
static String |
substring(String str,
char delimiterOfInclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substring(String str,
int inclusiveBeginIndex)
Returns
null if inclusiveBeginIndex < 0,
otherwise the substring with String value: str.substring(inclusiveBeginIndex) is returned. |
static String |
substring(String str,
int inclusiveBeginIndex,
char delimiterOfExclusiveEndIndex) |
static String |
substring(String str,
int inclusiveBeginIndex,
int exclusiveEndIndex)
Returns
null if inclusiveBeginIndex < 0 || exclusiveEndIndex < 0 || inclusiveBeginIndex > exclusiveEndIndex,
otherwise the substring with String value: str.substring(exclusiveBeginIndex, exclusiveEndIndex) is returned. |
static String |
substring(String str,
int inclusiveBeginIndex,
IntUnaryOperator funcOfExclusiveEndIndex) |
static String |
substring(String str,
int inclusiveBeginIndex,
String delimiterOfExclusiveEndIndex) |
static String |
substring(String str,
IntUnaryOperator funcOfInclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substring(String str,
String delimiterOfInclusiveBeginIndex)
Returns
null if N.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0,
otherwise the substring with String value: str.substring(str.indexOf(delimiterOfInclusiveBeginIndex)) is returned. |
static String |
substring(String str,
String delimiterOfInclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substringAfter(String str,
String delimiterOfExclusiveBeginIndex)
Returns the substring after first
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String. |
static String |
substringAfterLast(String str,
String delimiterOfExclusiveBeginIndex)
Returns the substring after last
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String. |
static String |
substringBefore(String str,
String delimiterOfExclusiveEndIndex)
Returns the substring before first
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String. |
static String |
substringBeforeLast(String str,
String delimiterOfExclusiveEndIndex)
Returns the substring before last
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String. |
static String |
substringBetween(String str,
char delimiterOfExclusiveBeginIndex,
char delimiterOfExclusiveEndIndex) |
static String |
substringBetween(String str,
char delimiterOfExclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substringBetween(String str,
int exclusiveBeginIndex,
char delimiterOfExclusiveEndIndex) |
static String |
substringBetween(String str,
int exclusiveBeginIndex,
int exclusiveEndIndex)
Returns
null if exclusiveBeginIndex < 0 || exclusiveEndIndex < 0 || exclusiveBeginIndex >= exclusiveEndIndex,
otherwise the substring with String value: str.substring(exclusiveBeginIndex + 1, exclusiveEndIndex) is returned. |
static String |
substringBetween(String str,
int exclusiveBeginIndex,
IntUnaryOperator funcOfExclusiveEndIndex) |
static String |
substringBetween(String str,
int exclusiveBeginIndex,
String delimiterOfExclusiveEndIndex) |
static String |
substringBetween(String str,
IntUnaryOperator funcOfExclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substringBetween(String str,
String delimiterOfExclusiveBeginIndex,
int exclusiveEndIndex) |
static String |
substringBetween(String str,
String delimiterOfExclusiveBeginIndex,
String delimiterOfExclusiveEndIndex) |
static char |
swapCase(char ch) |
static String |
swapCase(String str)
Swaps the case of a String changing upper and title case to lower case,
and lower case to upper case.
|
static String |
toCamelCase(String str) |
static char[] |
toCharArray(CharSequence source) |
static int[] |
toCodePoints(CharSequence str)
Converts a
CharSequence into an array of code points. |
static char |
toLowerCase(char ch)
To lower case.
|
static String |
toLowerCase(String str)
Converts a String to lower case as per
String.toLowerCase(). |
static String |
toLowerCase(String str,
Locale locale)
Converts a String to lower case as per
String.toLowerCase(Locale)
. |
static String |
toLowerCaseWithUnderscore(String str)
To lower case with underscore.
|
static char |
toUpperCase(char ch)
To upper case.
|
static String |
toUpperCase(String str)
Converts a String to upper case as per
String.toUpperCase(). |
static String |
toUpperCase(String str,
Locale locale)
Converts a String to upper case as per
String.toUpperCase(Locale)
. |
static String |
toUpperCaseWithUnderscore(String str)
To upper case with underscore.
|
static String |
trim(String str)
Removes control characters (char <= 32) from both ends of this String,
handling
null by returning null. |
static void |
trim(String[] strs) |
static String |
trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String
returning an empty String ("") if the String is empty ("") after the trim
or if it is
null. |
static void |
trimToEmpty(String[] strs) |
static String |
trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String
returning
null if the String is empty ("") after the trim or if
it is null. |
static void |
trimToNull(String[] strs) |
static String |
truncate(String str,
int maxWidth)
Truncates a String.
|
static String |
truncate(String str,
int offset,
int maxWidth)
Truncates a String.
|
static String |
uncapitalize(String str) |
static String |
unicodeEscaped(char ch)
Converts the char to the unicode format ' '.
|
static String |
unwrap(String str,
String prefixSuffix) |
static String |
unwrap(String str,
String prefix,
String suffix)
Unwraps the specified string
str if and only if it's wrapped by the specified prefix and suffix |
static String |
valueOf(char[] value)
Returns the string representation of the
char array or null. |
static String |
wrap(String str,
String prefixSuffix) |
static String |
wrap(String str,
String prefix,
String suffix)
N.wrap(null, "[", "]") -> "[]"
N.wrap("", "[", "]") -> "[]"
N.wrap("[", "[", "]") -> "[[]"
N.wrap("]", "[", "]") -> "[]]"
N.wrap("abc", "[", "]") -> "[abc]"
N.wrap("a", "aa", "aa") -> "aaaaa"
N.wrap("aa", "aa", "aa") -> "aaaaaa"
N.wrap("aaa", "aa", "aa") -> "aaaaaaa"
|
static String |
wrapIfMissing(String str,
String prefixSuffix)
Wrap if missing.
|
static String |
wrapIfMissing(String str,
String prefix,
String suffix)
N.wrapIfMissing(null, "[", "]") -> "[]"
N.wrapIfMissing("", "[", "]") -> "[]"
N.wrapIfMissing("[", "[", "]") -> "[]"
N.wrapIfMissing("]", "[", "]") -> "[]"
N.wrapIfMissing("abc", "[", "]") -> "[abc]"
N.wrapIfMissing("a", "aa", "aa") -> "aaaaa"
N.wrapIfMissing("aa", "aa", "aa") -> "aaaa"
N.wrapIfMissing("aaa", "aa", "aa") -> "aaaaa"
N.wrapIfMissing("aaaa", "aa", "aa") -> "aaaa"
|
public static final String EMPTY
"".public static final String SPACE
public static final String LF
public static final String CR
public static String valueOf(char[] value)
char array or null.value - the character array.String.valueOf(char[])public static boolean isEmpty(CharSequence cs)
N.isNullOrEmpty(CharSequence).cs - CommonUtil.isNullOrEmpty(CharSequence)public static boolean isBlank(CharSequence cs)
N.isNullOrEmptyOrBlank(CharSequence).cs - CommonUtil.isNullOrEmptyOrBlank(CharSequence)public static boolean isNotEmpty(CharSequence cs)
N.notNullOrEmpty(CharSequence).cs - CommonUtil.notNullOrEmpty(CharSequence)public static boolean isNotBlank(CharSequence cs)
N.notNullOrEmptyOrBlank(CharSequence).cs - CommonUtil.notNullOrEmptyOrBlank(CharSequence)public static boolean isAllEmpty(CharSequence... css)
Checks if all of the CharSequences are empty ("") or null.
StringUtil.isAllEmpty(null) = true
StringUtil.isAllEmpty(null, "") = true
StringUtil.isAllEmpty(new String[] {}) = true
StringUtil.isAllEmpty(null, "foo") = false
StringUtil.isAllEmpty("", "bar") = false
StringUtil.isAllEmpty("bob", "") = false
StringUtil.isAllEmpty(" bob ", null) = false
StringUtil.isAllEmpty(" ", "bar") = false
StringUtil.isAllEmpty("foo", "bar") = false
css - the CharSequences to check, may be null or emptytrue if all of the CharSequences are empty or nullpublic static boolean isAllBlank(CharSequence... css)
Checks if all of the CharSequences are empty (""), null or whitespace only.
Whitespace is defined by Character.isWhitespace(char).
StringUtil.isAllBlank(null) = true
StringUtil.isAllBlank(null, "foo") = false
StringUtil.isAllBlank(null, null) = true
StringUtil.isAllBlank("", "bar") = false
StringUtil.isAllBlank("bob", "") = false
StringUtil.isAllBlank(" bob ", null) = false
StringUtil.isAllBlank(" ", "bar") = false
StringUtil.isAllBlank("foo", "bar") = false
StringUtil.isAllBlank(new String[] {}) = true
css - the CharSequences to check, may be null or emptytrue if all of the CharSequences are empty or null or whitespace onlypublic static boolean isAnyEmpty(CharSequence... css)
Checks if any of the CharSequences are empty ("") or null.
StringUtil.isAnyEmpty((String) null) = true
StringUtil.isAnyEmpty((String[]) null) = false
StringUtil.isAnyEmpty(null, "foo") = true
StringUtil.isAnyEmpty("", "bar") = true
StringUtil.isAnyEmpty("bob", "") = true
StringUtil.isAnyEmpty(" bob ", null) = true
StringUtil.isAnyEmpty(" ", "bar") = false
StringUtil.isAnyEmpty("foo", "bar") = false
StringUtil.isAnyEmpty(new String[]{}) = false
StringUtil.isAnyEmpty(new String[]{""}) = true
css - the CharSequences to check, may be null or emptytrue if any of the CharSequences are empty or nullpublic static boolean isAnyBlank(CharSequence... css)
Checks if any of the CharSequences are empty ("") or null or whitespace only.
Whitespace is defined by Character.isWhitespace(char).
StringUtil.isAnyBlank((String) null) = true
StringUtil.isAnyBlank((String[]) null) = false
StringUtil.isAnyBlank(null, "foo") = true
StringUtil.isAnyBlank(null, null) = true
StringUtil.isAnyBlank("", "bar") = true
StringUtil.isAnyBlank("bob", "") = true
StringUtil.isAnyBlank(" bob ", null) = true
StringUtil.isAnyBlank(" ", "bar") = true
StringUtil.isAnyBlank(new String[] {}) = false
StringUtil.isAnyBlank(new String[]{""}) = true
StringUtil.isAnyBlank("foo", "bar") = false
css - the CharSequences to check, may be null or emptytrue if any of the CharSequences are empty or null or whitespace onlypublic static <T extends CharSequence> T defaultIfEmpty(T str, T defaultStr)
N.defaultIfNullOrEmpty(CharSequence, CharSequence).T - str - defaultStr - CommonUtil.defaultIfNullOrEmpty(CharSequence, CharSequence)public static <T extends CharSequence> T defaultIfEmpty(T str, Supplier<? extends T> getterForDefaultStr)
T - str - getterForDefaultStr - public static <T extends CharSequence> T defaultIfBlank(T str, T defaultStr)
N.defaultIfNullOrEmptyOrBlank(CharSequence, CharSequence).T - str - defaultStr - CommonUtil.defaultIfNullOrEmptyOrBlank(CharSequence, CharSequence)public static <T extends CharSequence> T defaultIfBlank(T str, Supplier<? extends T> getterForDefaultStr)
T - str - getterForDefaultStr - @SafeVarargs public static <T extends CharSequence> T firstNonBlank(T... values)
@SafeVarargs public static <T extends CharSequence> T firstNonEmpty(T... values)
Returns the first value in the array which is not empty.
If all values are empty or the array is null
or empty then null is returned.
StringUtil.firstNonEmpty(null, null, null) = null
StringUtil.firstNonEmpty(null, null, "") = null
StringUtil.firstNonEmpty(null, "", " ") = " "
StringUtil.firstNonEmpty("abc") = "abc"
StringUtil.firstNonEmpty(null, "xyz") = "xyz"
StringUtil.firstNonEmpty("", "xyz") = "xyz"
StringUtil.firstNonEmpty(null, "xyz", "abc") = "xyz"
StringUtil.firstNonEmpty() = null
T - the specific kind of CharSequencevalues - the values to test, may be null or emptyvalues which is not empty,
or null if there are no non-empty valuespublic static String abbreviate(String str, int maxWidth)
Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."
Specifically:
str is less than or equal to
maxWidth, return str.(substring(str, 0, max-3) + "...").maxWidth is less than 4, throw an
IllegalArgumentException.maxWidth.
StringUtil.abbreviate(null, 4) = null
StringUtil.abbreviate("", 4) = ""
StringUtil.abbreviate("abcdefg", 6) = "abc..."
StringUtil.abbreviate("abcdefg", 7) = "abcdefg"
StringUtil.abbreviate("abcdefg", 8) = "abcdefg"
StringUtil.abbreviate("abcdefg", 4) = "a..."
StringUtil.abbreviate("abcdefg", 3) = IllegalArgumentException
str - the String to check, may be nullmaxWidth - maximum length of result String, must be at least 4IllegalArgumentException - if the width is too smallpublic static void nullToEmpty(String[] strs)
public static void emptyToNull(String[] strs)
public static String abbreviate(String str, String abbrevMarker, int maxWidth)
Abbreviates a String using another given String as replacement marker. This will turn "Now is the time for all good men" into "Now is the time for..." if "..." was defined as the replacement marker.
Specifically:
str is less than or equal to
maxWidth, return str.(substring(str, 0, max-abbrevMarker.length) + abbrevMarker).maxWidth is less than abbrevMarker.length + 1, throw an
IllegalArgumentException.maxWidth.
StringUtil.abbreviate(null, "...", 4) = null
StringUtil.abbreviate("", "...", 4) = ""
StringUtil.abbreviate("abcdefg", null, *) = "abcdefg"
StringUtil.abbreviate("abcdefg", ".", 5) = "abcd."
StringUtil.abbreviate("abcdefg", ".", 7) = "abcdefg"
StringUtil.abbreviate("abcdefg", ".", 8) = "abcdefg"
StringUtil.abbreviate("abcdefg", "..", 4) = "ab.."
StringUtil.abbreviate("abcdefg", "..", 3) = "a.."
StringUtil.abbreviate("abcdefg", "..", 2) = IllegalArgumentException
StringUtil.abbreviate("abcdefg", "...", 3) = IllegalArgumentException
str - the String to check, may be nullabbrevMarker - the String used as replacement markermaxWidth - maximum length of result String, must be at least abbrevMarker.length + 1IllegalArgumentException - if the width is too smallpublic static String abbreviateMiddle(String str, String middle, int length)
Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String.
This abbreviation only occurs if the following criteria is met:
Otherwise, the returned String will be the same as the supplied String for abbreviation.
StringUtil.abbreviateMiddle(null, null, 0) = null
StringUtil.abbreviateMiddle("abc", null, 0) = "abc"
StringUtil.abbreviateMiddle("abc", ".", 0) = "abc"
StringUtil.abbreviateMiddle("abc", ".", 3) = "abc"
StringUtil.abbreviateMiddle("abcdef", ".", 4) = "ab.f"
str - the String to abbreviate, may be nullmiddle - the String to replace the middle characters with, may be nulllength - the length to abbreviate str to.public static String center(String str, int size)
Centers a String in a larger String of size size
using the space character (' ').
If the size is less than the String length, the original String is returned.
Equivalent to center(str, size, " ").
StringUtil.center(null, 4) = " "
StringUtil.center("", 4) = " "
StringUtil.center("ab", 4) = " ab "
StringUtil.center("abcd", 2) = "abcd"
StringUtil.center("a", 4) = " a "
str - the String to center, may be nullsize - the int size of new Stringpublic static String center(String str, int size, char padChar)
Centers a String in a larger String of size size.
Uses a supplied character as the value to pad the String with.
If the size is less than the String length, the String is returned.
StringUtil.center(null, 4, ' ') = " "
StringUtil.center("", 4, ' ') = " "
StringUtil.center("ab", 4, ' ') = " ab "
StringUtil.center("abcd", 2, ' ') = "abcd"
StringUtil.center("a", 4, ' ') = " a "
StringUtil.center("a", 4, 'y') = "yayy"
str - the String to center, may be nullsize - the int size of new String.padChar - the character to pad the new String withpublic static String center(String str, int minLength, String padStr)
Centers a String in a larger String of size minLength.
Uses a supplied String as the value to pad the String with.
If the size is less than the String length, the String is returned.
StringUtil.center(null, 4, " ") = " "
StringUtil.center("", 4, " ") = " "
StringUtil.center("ab", 4, " ") = " ab "
StringUtil.center("abcd", 2, " ") = "abcd"
StringUtil.center("a", 4, " ") = " a "
StringUtil.center("a", 4, "yz") = "yzayz"
StringUtil.center("abc", 7, "") = " abc "
str - the String to center, may be nullminLength - the minimum size of new String.padStr - the String to pad the new String with, must not be null or emptypublic static String padStart(String str, int minLength)
str - minLength - public static String padStart(String str, int minLength, char padChar)
str - minLength - padChar - public static String padStart(String str, int minLength, String padStr)
str - minLength - padStr - public static String padEnd(String str, int minLength)
str - minLength - public static String padEnd(String str, int minLength, char padChar)
str - minLength - padChar - public static String padEnd(String str, int minLength, String padStr)
str - minLength - padStr - public static String repeat(char ch, int n)
ch - n - public static String repeat(char ch, int n, char delimiter)
ch - n - delimiter - public static String repeat(String str, int n, String delimiter)
str - n - delimiter - public static String repeat(String str, int n, String delimiter, String prefix, String suffix)
str - n - delimiter - prefix - suffix - public static char toLowerCase(char ch)
ch - public static String toLowerCase(String str)
Converts a String to lower case as per String.toLowerCase().
A null input String returns null.
StringUtil.toLowerCase(null) = null
StringUtil.toLowerCase("") = ""
StringUtil.toLowerCase("aBc") = "abc"
Note: As described in the documentation for
String.toLowerCase(), the result of this method is affected by
the current locale. For platform-independent case transformations, the
method toLowerCase(String, Locale) should be used with a specific
locale (e.g. Locale.ENGLISH).
str - the String to lower case, may be nullpublic static String toLowerCase(String str, Locale locale)
Converts a String to lower case as per String.toLowerCase(Locale)
.
A null input String returns null.
StringUtil.toLowerCase(null, Locale.ENGLISH) = null
StringUtil.toLowerCase("", Locale.ENGLISH) = ""
StringUtil.toLowerCase("aBc", Locale.ENGLISH) = "abc"
str - the String to lower case, may be nulllocale - the locale that defines the case transformation rules, must
not be nullpublic static String toLowerCaseWithUnderscore(String str)
str - public static char toUpperCase(char ch)
ch - public static String toUpperCase(String str)
Converts a String to upper case as per String.toUpperCase().
A null input String returns null.
N.toUpperCase(null) = null
N.toUpperCase("") = ""
N.toUpperCase("aBc") = "ABC"
Note: As described in the documentation for
String.toUpperCase(), the result of this method is affected by
the current locale. For platform-independent case transformations, the
method toLowerCase(String, Locale) should be used with a specific
locale (e.g. Locale.ENGLISH).
str - the String to upper case, may be nullpublic static String toUpperCase(String str, Locale locale)
Converts a String to upper case as per String.toUpperCase(Locale)
.
A null input String returns null.
N.toUpperCase(null, Locale.ENGLISH) = null
N.toUpperCase("", Locale.ENGLISH) = ""
N.toUpperCase("aBc", Locale.ENGLISH) = "ABC"
str - the String to upper case, may be nulllocale - the locale that defines the case transformation rules, must
not be nullpublic static String toUpperCaseWithUnderscore(String str)
str - public static char[] toCharArray(CharSequence source)
public static int[] toCodePoints(CharSequence str)
Converts a CharSequence into an array of code points.
Valid pairs of surrogate code units will be converted into a single supplementary code point. Isolated surrogate code units (i.e. a high surrogate not followed by a low surrogate or a low surrogate not preceded by a high surrogate) will be returned as-is.
StringUtil.toCodePoints(null) = [] // empty array
StringUtil.toCodePoints("") = [] // empty array
str - the character sequence to convertstr is null or empty.public static char swapCase(char ch)
ch - public static String swapCase(String str)
Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.
For a word based algorithm, see
org.apache.commons.lang3.text.WordUtils#swapCase(String). A
null input String returns null.
N.swapCase(null) = null
N.swapCase("") = ""
N.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
NOTE: This method changed in Lang version 2.0. It no longer performs a word based algorithm. If you only use ASCII, you will notice no change. That functionality is available in org.apache.commons.lang3.text.WordUtils.
str - the String to swap case, may be nullpublic static String quoteEscaped(String str)
null or empty.str - public static String unicodeEscaped(char ch)
Converts the char to the unicode format ' '.
This format is the Java source code format.
StringUtil.unicodeEscaped(' ') = " "
StringUtil.unicodeEscaped('A') = "A"
ch - the character to convertpublic static String normalizeSpace(String str)
Similar to http://www.w3.org/TR/xpath/#function-normalize -space
The function returns the argument string with whitespace normalized by
using to remove leading and trailing
whitespace and then replacing sequences of whitespace characters by a
single space.
trim(String)
Java's regexp pattern \s defines whitespace as [ \t\n\x0B\f\r]
For reference:
The difference is that Java's whitespace includes vertical tab and form
feed, which this functional will also normalize. Additionally
removes control characters (char <=
32) from both ends of this String.
trim(String)
str - the source String to normalize whitespaces from, may be nullPattern,
trim(String),
http://www.w3.org/TR/xpath/#function-normalize-spacepublic static String replaceAll(String str, String target, String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
N.replaceAll(null, *, *) = null
N.replaceAll("", *, *) = ""
N.replaceAll("any", null, *) = "any"
N.replaceAll("any", *, null) = "any"
N.replaceAll("any", "", *) = "any"
N.replaceAll("aba", "a", null) = "b"
N.replaceAll("aba", "a", "") = "b"
N.replaceAll("aba", "a", "z") = "zbz"
str - text to search and replace in, may be nulltarget - the String to search for, may be nullreplacement - the String to replace it with, may be null#replaceAll(String text, String searchString, String replacement,
int max)public static String replaceAll(String str, int fromIndex, String target, String replacement)
str - fromIndex - target - replacement - public static String replaceOnce(String str, String target, String replacement)
Replaces a String with another String inside a larger String, once.
A null reference passed to this method is a no-op.
StringUtil.replaceOnce(null, *, *) = null
StringUtil.replaceOnce("", *, *) = ""
StringUtil.replaceOnce("any", null, *) = "any"
StringUtil.replaceOnce("any", *, null) = "any"
StringUtil.replaceOnce("any", "", *) = "any"
StringUtil.replaceOnce("aba", "a", null) = "ba"
StringUtil.replaceOnce("aba", "a", "") = "ba"
StringUtil.replaceOnce("aba", "a", "z") = "zba"
text - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace with, may be nullnull if null String input#replace(String text, String searchString, String replacement, int max)public static String replaceOnce(String str, int fromIndex, String target, String replacement)
str - fromIndex - target - replacement - public static String replace(String str, int fromIndex, String target, String replacement, int max)
Replaces a String with another String inside a larger String, for the
first max values of the search String.
A null reference passed to this method is a no-op.
replace(null, *, *, *) = null
replace("", *, *, *) = ""
replace("any", null, *, *) = "any"
replace("any", "", *, *) = "any"
replace("any", *, *, 0) = "any"
replace("abaa", 0, "a", null, -1) = "b"
replace("abaa", 0, "a", "", -1) = "b"
replace("abaa", 0, "a", "z", 0) = "abaa"
replace("abaa", 0, "a", "z", 1) = "zbaa"
replace("abaa", 0, "a", "z", 2) = "zbza"
replace("abaa", 0, "a", "z", -1) = "zbzz"
str - text to search and replace in, may be nullfromIndex - target - the String to search for, may be nullreplacement - the String to replace it with, can't be nullmax - maximum number of values to replace, or -1 if no
maximumpublic static String replaceAllIgnoreCase(String str, String target, String replacement)
str - target - replacement - public static String replaceAllIgnoreCase(String str, int fromIndex, String target, String replacement)
str - fromIndex - target - replacement - public static String replaceOnceIgnoreCase(String str, String target, String replacement)
str - target - replacement - public static String replaceOnceIgnoreCase(String str, int fromIndex, String target, String replacement)
str - fromIndex - target - replacement - public static String replaceIgnoreCase(String str, int fromIndex, String target, String replacement, int max)
str - fromIndex - target - replacement - max - public static String replacePattern(String source, String regex, String replacement)
Pattern.DOTALL option. DOTALL is also know as single-line mode in
Perl. This call is also equivalent to:
source.replaceAll("(?s)" + regex, replacement)Pattern.compile(regex, Pattern.DOTALL).filter(source).replaceAll(replacement)
source - the source stringregex - the regular expression to which this string is to be matchedreplacement - the string to be substituted for each matchStringString.replaceAll(String, String),
Pattern.DOTALLpublic static String removeStart(String str, String removeStr)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null. An empty ("")
source string will return the empty string. A null search string
will return the source string.
N.removeStart(null, *) = null
N.removeStart("", *) = ""
N.removeStart(*, null) = *
N.removeStart("www.domain.com", "www.") = "domain.com"
N.removeStart("domain.com", "www.") = "domain.com"
N.removeStart("www.domain.com", "domain") = "www.domain.com"
N.removeStart("abc", "") = "abc"
str - the source String to search, may be nullremoveStr - the String to search for and remove, may be nullpublic static String removeStartIgnoreCase(String str, String removeStr)
Case insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null. An empty ("")
source string will return the empty string. A null search string
will return the source string.
N.removeStartIgnoreCase(null, *) = null
N.removeStartIgnoreCase("", *) = ""
N.removeStartIgnoreCase(*, null) = *
N.removeStartIgnoreCase("www.domain.com", "www.") = "domain.com"
N.removeStartIgnoreCase("www.domain.com", "WWW.") = "domain.com"
N.removeStartIgnoreCase("domain.com", "www.") = "domain.com"
N.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com"
N.removeStartIgnoreCase("abc", "") = "abc"
str - the source String to search, may be nullremoveStr - the String to search for (case insensitive) and remove, may be
nullpublic static String removeEnd(String str, String removeStr)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty ("")
source string will return the empty string. A null search string
will return the source string.
N.removeEnd(null, *) = null
N.removeEnd("", *) = ""
N.removeEnd(*, null) = *
N.removeEnd("www.domain.com", ".com.") = "www.domain.com"
N.removeEnd("www.domain.com", ".com") = "www.domain"
N.removeEnd("www.domain.com", "domain") = "www.domain.com"
N.removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremoveStr - the String to search for and remove, may be nullpublic static String removeEndIgnoreCase(String str, String removeStr)
Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.
A null source string will return null. An empty ("")
source string will return the empty string. A null search string
will return the source string.
N.removeEndIgnoreCase(null, *) = null
N.removeEndIgnoreCase("", *) = ""
N.removeEndIgnoreCase(*, null) = *
N.removeEndIgnoreCase("www.domain.com", ".com.") = "www.domain.com"
N.removeEndIgnoreCase("www.domain.com", ".com") = "www.domain"
N.removeEndIgnoreCase("www.domain.com", "domain") = "www.domain.com"
N.removeEndIgnoreCase("abc", "") = "abc"
N.removeEndIgnoreCase("www.domain.com", ".COM") = "www.domain")
N.removeEndIgnoreCase("www.domain.COM", ".com") = "www.domain")
str - the source String to search, may be nullremoveStr - the String to search for (case insensitive) and remove, may be
nullpublic static String removeAll(String str, char removeChar)
Removes all occurrences of a character from within the source string.
A null source string will return null. An empty ("")
source string will return the empty string.
N.remove(null, *) = null
N.remove("", *) = ""
N.remove("queued", 'u') = "qeed"
N.remove("queued", 'z') = "queued"
str - the source String to search, may be nullremoveChar - the char to search for and remove, may be nullpublic static String removeAll(String str, int fromIndex, char removeChar)
str - fromIndex - removeChar - public static String removeAll(String str, String removeStr)
Removes all occurrences of a substring from within the source string.
A null source string will return null. An empty ("")
source string will return the empty string. A null remove string
will return the source string. An empty ("") remove string will return
the source string.
N.remove(null, *) = null
N.remove("", *) = ""
N.remove(*, null) = *
N.remove(*, "") = *
N.remove("queued", "ue") = "qd"
N.remove("queued", "zz") = "queued"
str - the source String to search, may be nullremoveStr - the String to search for and remove, may be nullpublic static String removeAll(String str, int fromIndex, String removeStr)
str - fromIndex - removeStr - public static String removePattern(String source, String regex)
source - the source stringregex - the regular expression to which this string is to be matchedStringString.replaceAll(String, String),
Pattern.DOTALLpublic static String[] split(String str, char delimiter)
str - delimiter - public static String[] split(String str, char delimiter, boolean trim)
str - delimiter - trim - public static String[] split(String str, String delimiter)
str - delimiter - public static String[] split(String str, String delimiter, boolean trim)
str - delimiter - trim - @Deprecated public static String[] split(String str, String delimiter, int max)
Splitter is recommended.str - delimiter - max - @Deprecated public static String[] split(String str, String delimiter, int max, boolean trim)
Splitter is recommended.str - delimiter - max - trim - public static String[] splitPreserveAllTokens(String str, char delimiter)
str - delimiter - public static String[] splitPreserveAllTokens(String str, char delimiter, boolean trim)
str - delimiter - trim - public static String[] splitPreserveAllTokens(String str, String delimiter)
str - delimiter - public static String[] splitPreserveAllTokens(String str, String delimiter, boolean trim)
str - delimiter - trim - @Deprecated public static String[] splitPreserveAllTokens(String str, String delimiter, int max)
Splitter is recommended.str - delimiter - max - @Deprecated public static String[] splitPreserveAllTokens(String str, String delimiter, int max, boolean trim)
Splitter is recommended.str - delimiter - max - trim - public 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. To strip whitespace use strip(String).
To trim your choice of characters, use the strip(String, String)
methods.
StringUtil.trim(null) = null
StringUtil.trim("") = ""
StringUtil.trim(" ") = ""
StringUtil.trim("abc") = "abc"
StringUtil.trim(" abc ") = "abc"
str - the String to be trimmed, may be nullpublic static void trim(String[] strs)
public static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String
returning null if the String is empty ("") after the trim or if
it is null.
The String is trimmed using String.trim(). Trim removes start and
end characters <= 32. To strip whitespace use
stripToNull(String).
N.trimToNull(null) = null
N.trimToNull("") = null
N.trimToNull(" ") = null
N.trimToNull("abc") = "abc"
N.trimToNull(" abc ") = "abc"
str - the String to be trimmed, may be nullpublic static void trimToNull(String[] strs)
public static String trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String
returning an empty String ("") if the String is empty ("") after the trim
or if it is null.
The String is trimmed using String.trim(). Trim removes start and
end characters <= 32. To strip whitespace use
stripToEmpty(String).
N.trimToEmpty(null) = ""
N.trimToEmpty("") = ""
N.trimToEmpty(" ") = ""
N.trimToEmpty("abc") = "abc"
N.trimToEmpty(" abc ") = "abc"
str - the String to be trimmed, may be nullpublic static void trimToEmpty(String[] strs)
public static String strip(String str)
Strips whitespace from the start and end of a String.
This is similar to trim(String) but removes whitespace.
Whitespace is defined by Character.isWhitespace(char).
A null input String returns null.
N.strip(null) = null
N.strip("") = ""
N.strip(" ") = ""
N.strip("abc") = "abc"
N.strip(" abc") = "abc"
N.strip("abc ") = "abc"
N.strip(" abc ") = "abc"
N.strip(" ab c ") = "ab c"
str - the String to remove whitespace from, may be nullpublic static void strip(String[] strs)
public static String stripToNull(String str)
Strips whitespace from the start and end of a String returning
null if the String is empty ("") after the strip.
This is similar to trimToNull(String) but removes whitespace.
Whitespace is defined by Character.isWhitespace(char).
N.stripToNull(null) = null
N.stripToNull("") = null
N.stripToNull(" ") = null
N.stripToNull("abc") = "abc"
N.stripToNull(" abc") = "abc"
N.stripToNull("abc ") = "abc"
N.stripToNull(" abc ") = "abc"
N.stripToNull(" ab c ") = "ab c"
str - the String to be stripped, may be nullpublic static void stripToNull(String[] strs)
public static String stripToEmpty(String str)
Strips whitespace from the start and end of a String returning an empty
String if null input.
This is similar to trimToEmpty(String) but removes whitespace.
Whitespace is defined by Character.isWhitespace(char).
N.stripToEmpty(null) = ""
N.stripToEmpty("") = ""
N.stripToEmpty(" ") = ""
N.stripToEmpty("abc") = "abc"
N.stripToEmpty(" abc") = "abc"
N.stripToEmpty("abc ") = "abc"
N.stripToEmpty(" abc ") = "abc"
N.stripToEmpty(" ab c ") = "ab c"
str - the String to be stripped, may be nullpublic static void stripToEmpty(String[] strs)
public static String strip(String str, String stripChars)
Strips any of a set of characters from the start and end of a String.
This is similar to String.trim() but allows the characters to be
stripped to be controlled.
A null input String returns null. An empty string ("")
input returns the empty string.
If the stripChars String is null, whitespace is stripped as
defined by Character.isWhitespace(char). Alternatively use
strip(String).
N.strip(null, *) = null
N.strip("", *) = ""
N.strip("abc", null) = "abc"
N.strip(" abc", null) = "abc"
N.strip("abc ", null) = "abc"
N.strip(" abc ", null) = "abc"
N.strip(" abcyx", "xyz") = " abc"
str - the String to remove characters from, may be nullstripChars - the characters to remove, null treated as whitespacepublic static String stripStart(String str, String stripChars)
Strips any of a set of characters from the start of a String.
A null input String returns null. An empty string ("")
input returns the empty string.
If the stripChars String is null, whitespace is stripped as
defined by Character.isWhitespace(char).
N.stripStart(null, *) = null
N.stripStart("", *) = ""
N.stripStart("abc", "") = "abc"
N.stripStart("abc", null) = "abc"
N.stripStart(" abc", null) = "abc"
N.stripStart("abc ", null) = "abc "
N.stripStart(" abc ", null) = "abc "
N.stripStart("yxabc ", "xyz") = "abc "
str - the String to remove characters from, may be nullstripChars - the characters to remove, null treated as whitespacepublic static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
A null input String returns null. An empty string ("")
input returns the empty string.
If the stripChars String is null, whitespace is stripped as
defined by Character.isWhitespace(char).
N.stripEnd(null, *) = null
N.stripEnd("", *) = ""
N.stripEnd("abc", "") = "abc"
N.stripEnd("abc", null) = "abc"
N.stripEnd(" abc", null) = " abc"
N.stripEnd("abc ", null) = "abc"
N.stripEnd(" abc ", null) = " abc"
N.stripEnd(" abcyx", "xyz") = " abc"
N.stripEnd("120.00", ".0") = "12"
str - the String to remove characters from, may be nullstripChars - the set of characters to remove, null treated as whitespacepublic static String stripAccents(String str)
Removes diacritics (~= accents) from a string. The case will not be altered.
For instance, 'à' will be replaced by 'a'.
Note that ligatures will be left as is.
N.stripAccents(null) = null
N.stripAccents("") = ""
N.stripAccents("control") = "control"
N.stripAccents("éclair") = "eclair"
str - public static void stripAccents(String[] strs)
public static String chomp(String str)
Removes one newline from end of a String if it's there, otherwise leave
it alone. A newline is "\n ", "\r",
or "\r\n".
NOTE: This method changed in 2.0. It now more closely matches Perl chomp.
N.chomp(null) = null
N.chomp("") = ""
N.chomp("abc \r") = "abc "
N.chomp("abc\n") = "abc"
N.chomp("abc\r\n") = "abc"
N.chomp("abc\r\n\r\n") = "abc\r\n"
N.chomp("abc\n\r") = "abc\n"
N.chomp("abc\n\rabc") = "abc\n\rabc"
N.chomp("\r") = ""
N.chomp("\n") = ""
N.chomp("\r\n") = ""
str - the String to chomp a newline from, may be nullnull if null String inputpublic static void chomp(String[] strs)
public static String chop(String str)
Remove the last character from a String.
If the String ends in \r\n, then remove both of them.
StringUtil.chop(null) = null
StringUtil.chop("") = ""
StringUtil.chop("abc \r") = "abc "
StringUtil.chop("abc\n") = "abc"
StringUtil.chop("abc\r\n") = "abc"
StringUtil.chop("abc") = "ab"
StringUtil.chop("abc\nabc") = "abc\nab"
StringUtil.chop("a") = ""
StringUtil.chop("\r") = ""
StringUtil.chop("\n") = ""
StringUtil.chop("\r\n") = ""
str - the String to chop last character from, may be nullnull if null String inputpublic static void chop(String[] strs)
public static String truncate(String str, int maxWidth)
Truncates a String. This will turn "Now is the time for all good men" into "Now is the time for".
Specifically:
str is less than maxWidth characters
long, return it.substring(str, 0, maxWidth).maxWidth is less than 0, throw an
IllegalArgumentException.maxWidth.
StringUtil.truncate(null, 0) = null
StringUtil.truncate(null, 2) = null
StringUtil.truncate("", 4) = ""
StringUtil.truncate("abcdefg", 4) = "abcd"
StringUtil.truncate("abcdefg", 6) = "abcdef"
StringUtil.truncate("abcdefg", 7) = "abcdefg"
StringUtil.truncate("abcdefg", 8) = "abcdefg"
StringUtil.truncate("abcdefg", -1) = throws an IllegalArgumentException
str - the String to truncate, may be nullmaxWidth - maximum length of result String, must be positivenull if null String inputIllegalArgumentException - If maxWidth is less than 0public static String truncate(String str, int offset, int maxWidth)
Truncates a String. This will turn "Now is the time for all good men" into "is the time for all".
Works like truncate(String, int), but allows you to specify
a "left edge" offset.
Specifically:
str is less than maxWidth characters
long, return it.substring(str, offset, maxWidth).maxWidth is less than 0, throw an
IllegalArgumentException.offset is less than 0, throw an
IllegalArgumentException.maxWidth.
StringUtil.truncate(null, 0, 0) = null
StringUtil.truncate(null, 2, 4) = null
StringUtil.truncate("", 0, 10) = ""
StringUtil.truncate("", 2, 10) = ""
StringUtil.truncate("abcdefghij", 0, 3) = "abc"
StringUtil.truncate("abcdefghij", 5, 6) = "fghij"
StringUtil.truncate("raspberry peach", 10, 15) = "peach"
StringUtil.truncate("abcdefghijklmno", 0, 10) = "abcdefghij"
StringUtil.truncate("abcdefghijklmno", -1, 10) = throws an IllegalArgumentException
StringUtil.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = throws an IllegalArgumentException
StringUtil.truncate("abcdefghijklmno", Integer.MIN_VALUE, Integer.MAX_VALUE) = throws an IllegalArgumentException
StringUtil.truncate("abcdefghijklmno", 0, Integer.MAX_VALUE) = "abcdefghijklmno"
StringUtil.truncate("abcdefghijklmno", 1, 10) = "bcdefghijk"
StringUtil.truncate("abcdefghijklmno", 2, 10) = "cdefghijkl"
StringUtil.truncate("abcdefghijklmno", 3, 10) = "defghijklm"
StringUtil.truncate("abcdefghijklmno", 4, 10) = "efghijklmn"
StringUtil.truncate("abcdefghijklmno", 5, 10) = "fghijklmno"
StringUtil.truncate("abcdefghijklmno", 5, 5) = "fghij"
StringUtil.truncate("abcdefghijklmno", 5, 3) = "fgh"
StringUtil.truncate("abcdefghijklmno", 10, 3) = "klm"
StringUtil.truncate("abcdefghijklmno", 10, Integer.MAX_VALUE) = "klmno"
StringUtil.truncate("abcdefghijklmno", 13, 1) = "n"
StringUtil.truncate("abcdefghijklmno", 13, Integer.MAX_VALUE) = "no"
StringUtil.truncate("abcdefghijklmno", 14, 1) = "o"
StringUtil.truncate("abcdefghijklmno", 14, Integer.MAX_VALUE) = "o"
StringUtil.truncate("abcdefghijklmno", 15, 1) = ""
StringUtil.truncate("abcdefghijklmno", 15, Integer.MAX_VALUE) = ""
StringUtil.truncate("abcdefghijklmno", Integer.MAX_VALUE, Integer.MAX_VALUE) = ""
StringUtil.truncate("abcdefghij", 3, -1) = throws an IllegalArgumentException
StringUtil.truncate("abcdefghij", -2, 4) = throws an IllegalArgumentException
str - the String to truncate, may be nulloffset - left edge of source StringmaxWidth - maximum length of result String, must be positivenull if null String inputIllegalArgumentException - If offset or maxWidth is less than 0public static String deleteWhitespace(String str)
Deletes all white spaces from a String as defined by
Character.isWhitespace(char).
N.deleteWhitespace(null) = null
N.deleteWhitespace("") = ""
N.deleteWhitespace("abc") = "abc"
N.deleteWhitespace(" ab c ") = "abc"
str - the String to delete whitespace from, may be nullpublic static void deleteWhitespace(String[] strs)
public static String appendIfMissing(String str, String suffix)
str - suffix - public static String appendIfMissingIgnoreCase(String str, String suffix)
str - suffix - public static String prependIfMissing(String str, String prefix)
str - prefix - public static String prependIfMissingIgnoreCase(String str, String prefix)
public static String wrapIfMissing(String str, String prefixSuffix)
str - prefixSuffix - public static String wrapIfMissing(String str, String prefix, String suffix)
N.wrapIfMissing(null, "[", "]") -> "[]"
N.wrapIfMissing("", "[", "]") -> "[]"
N.wrapIfMissing("[", "[", "]") -> "[]"
N.wrapIfMissing("]", "[", "]") -> "[]"
N.wrapIfMissing("abc", "[", "]") -> "[abc]"
N.wrapIfMissing("a", "aa", "aa") -> "aaaaa"
N.wrapIfMissing("aa", "aa", "aa") -> "aaaa"
N.wrapIfMissing("aaa", "aa", "aa") -> "aaaaa"
N.wrapIfMissing("aaaa", "aa", "aa") -> "aaaa"
str - prefix - suffix - public static String wrap(String str, String prefixSuffix)
str - prefixSuffix - public static String wrap(String str, String prefix, String suffix)
N.wrap(null, "[", "]") -> "[]"
N.wrap("", "[", "]") -> "[]"
N.wrap("[", "[", "]") -> "[[]"
N.wrap("]", "[", "]") -> "[]]"
N.wrap("abc", "[", "]") -> "[abc]"
N.wrap("a", "aa", "aa") -> "aaaaa"
N.wrap("aa", "aa", "aa") -> "aaaaaa"
N.wrap("aaa", "aa", "aa") -> "aaaaaaa"
str - prefix - suffix - public static String unwrap(String str, String prefixSuffix)
str - prefixSuffix - public static String unwrap(String str, String prefix, String suffix)
Unwraps the specified string str if and only if it's wrapped by the specified prefix and suffix
N.unwrap(null, "[", "]") -> ""
N.unwrap("", "[", "]") -> ""
N.unwrap("[", "[", "]") -> "["
N.unwrap("]", "[", "]") -> "["
N.unwrap("[abc]", "[", "]") -> "abc"
N.unwrap("aaaaa", "aa", "aa") -> "a"
N.unwrap("aa", "aa", "aa") -> "aa"
N.unwrap("aaa", "aa", "aa") -> "aaa"
N.unwrap("aaaa", "aa", "aa") -> ""
str - prefix - suffix - public static boolean isLowerCase(char ch)
ch - public static boolean isAsciiLowerCase(char ch)
ch - public static boolean isUpperCase(char ch)
ch - public static boolean isAsciiUpperCase(char ch)
ch - public static boolean isAllLowerCase(CharSequence cs)
cs - public static boolean isAllUpperCase(CharSequence cs)
cs - public static boolean isMixedCase(CharSequence cs)
cs - public static boolean isDigit(char ch)
ch - Character.isDigit(char)public static boolean isLetter(char ch)
ch - Character.isLetter(char)public static boolean isLetterOrDigit(char ch)
ch - Character.isLetterOrDigit(char)public static boolean isAscii(char ch)
Checks whether the character is ASCII 7 bit.
StringUtil.isAscii('a') = true
StringUtil.isAscii('A') = true
StringUtil.isAscii('3') = true
StringUtil.isAscii('-') = true
StringUtil.isAscii('\n') = true
StringUtil.isAscii('©') = false
ch - the character to checkpublic static boolean isAsciiPrintable(char ch)
Checks whether the character is ASCII 7 bit printable.
StringUtil.isAsciiPrintable('a') = true
StringUtil.isAsciiPrintable('A') = true
StringUtil.isAsciiPrintable('3') = true
StringUtil.isAsciiPrintable('-') = true
StringUtil.isAsciiPrintable('\n') = false
StringUtil.isAsciiPrintable('©') = false
ch - the character to checkpublic static boolean isAsciiControl(char ch)
Checks whether the character is ASCII 7 bit control.
StringUtil.isAsciiControl('a') = false
StringUtil.isAsciiControl('A') = false
StringUtil.isAsciiControl('3') = false
StringUtil.isAsciiControl('-') = false
StringUtil.isAsciiControl('\n') = true
StringUtil.isAsciiControl('©') = false
ch - the character to checkpublic static boolean isAsciiAlpha(char ch)
Checks whether the character is ASCII 7 bit alphabetic.
StringUtil.isAsciiAlpha('a') = true
StringUtil.isAsciiAlpha('A') = true
StringUtil.isAsciiAlpha('3') = false
StringUtil.isAsciiAlpha('-') = false
StringUtil.isAsciiAlpha('\n') = false
StringUtil.isAsciiAlpha('©') = false
ch - the character to checkpublic static boolean isAsciiAlphaUpper(char ch)
Checks whether the character is ASCII 7 bit alphabetic upper case.
StringUtil.isAsciiAlphaUpper('a') = false
StringUtil.isAsciiAlphaUpper('A') = true
StringUtil.isAsciiAlphaUpper('3') = false
StringUtil.isAsciiAlphaUpper('-') = false
StringUtil.isAsciiAlphaUpper('\n') = false
StringUtil.isAsciiAlphaUpper('©') = false
ch - the character to checkpublic static boolean isAsciiAlphaLower(char ch)
Checks whether the character is ASCII 7 bit alphabetic lower case.
StringUtil.isAsciiAlphaLower('a') = true
StringUtil.isAsciiAlphaLower('A') = false
StringUtil.isAsciiAlphaLower('3') = false
StringUtil.isAsciiAlphaLower('-') = false
StringUtil.isAsciiAlphaLower('\n') = false
StringUtil.isAsciiAlphaLower('©') = false
ch - the character to checkpublic static boolean isAsciiNumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
StringUtil.isAsciiNumeric('a') = false
StringUtil.isAsciiNumeric('A') = false
StringUtil.isAsciiNumeric('3') = true
StringUtil.isAsciiNumeric('-') = false
StringUtil.isAsciiNumeric('\n') = false
StringUtil.isAsciiNumeric('©') = false
ch - the character to checkpublic static boolean isAsciiAlphanumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
StringUtil.isAsciiAlphanumeric('a') = true
StringUtil.isAsciiAlphanumeric('A') = true
StringUtil.isAsciiAlphanumeric('3') = true
StringUtil.isAsciiAlphanumeric('-') = false
StringUtil.isAsciiAlphanumeric('\n') = false
StringUtil.isAsciiAlphanumeric('©') = false
ch - the character to checkpublic static boolean isAsciiPrintable(CharSequence cs)
cs - public static boolean isAsciiAlpha(CharSequence cs)
cs - public static boolean isAsciiAlphaSpace(CharSequence cs)
cs - public static boolean isAsciiAlphanumeric(CharSequence cs)
cs - public static boolean isAsciiAlphanumericSpace(CharSequence cs)
cs - public static boolean isAsciiNumeric(CharSequence cs)
cs - public static boolean isAlpha(CharSequence cs)
Checks if the CharSequence contains only Unicode letters.
null or empty CharSequence (length()=0) will return false
.
N.isAlpha(null) = false
N.isAlpha("") = false
N.isAlpha(" ") = false
N.isAlpha("abc") = true
N.isAlpha("ab2c") = false
N.isAlpha("ab-c") = false
cs - the CharSequence to check, may be nulltrue if only contains letters, and is non-nullpublic static boolean isAlphaSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode letters and space (' ').
null or empty CharSequence (length()=0) will return false
.
N.isAlphaSpace(null) = false
N.isAlphaSpace("") = false
N.isAlphaSpace(" ") = true
N.isAlphaSpace("abc") = true
N.isAlphaSpace("ab c") = true
N.isAlphaSpace("ab2c") = false
N.isAlphaSpace("ab-c") = false
cs - the CharSequence to check, may be nulltrue if only contains letters and space, and is non-nullpublic static boolean isAlphanumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode letters or digits.
null or empty CharSequence (length()=0) will return false
.
N.isAlphanumeric(null) = false
N.isAlphanumeric("") = false
N.isAlphanumeric(" ") = false
N.isAlphanumeric("abc") = true
N.isAlphanumeric("ab c") = false
N.isAlphanumeric("ab2c") = true
N.isAlphanumeric("ab-c") = false
cs - the CharSequence to check, may be nulltrue if only contains letters or digits, and is non-nullpublic static boolean isAlphanumericSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode letters, digits or space
(' ').
null or empty CharSequence (length()=0) will return false
.
N.isAlphanumericSpace(null) = false
N.isAlphanumericSpace("") = false
N.isAlphanumericSpace(" ") = true
N.isAlphanumericSpace("abc") = true
N.isAlphanumericSpace("ab c") = true
N.isAlphanumericSpace("ab2c") = true
N.isAlphanumericSpace("ab-c") = false
cs - the CharSequence to check, may be nulltrue if only contains letters, digits or space, and is
non-nullpublic static boolean isNumeric(CharSequence cs)
Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false.
null will return false. An empty CharSequence
(length()=0) will return false.
Note that the method does not allow for a leading sign, either positive or negative. Also, if a String passes the numeric test, it may still generate a NumberFormatException when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range for int or long respectively.
N.isNumeric(null) = false
N.isNumeric("") = false
N.isNumeric(" ") = false
N.isNumeric("123") = true
N.isNumeric("12 3") = false
N.isNumeric("ab2c") = false
N.isNumeric("12-3") = false
N.isNumeric("12.3") = false
N.isNumeric("-123") = false
N.isNumeric("+123") = false
cs - the CharSequence to check, may be nulltrue if only contains digits, and is non-nullpublic static boolean isNumericSpace(CharSequence cs)
Checks if the CharSequence contains only Unicode digits or space (
' '). A decimal point is not a Unicode digit and returns false.
null or empty CharSequence (length()=0) will return false
.
N.isNumericSpace(null) = false
N.isNumericSpace("") = false
N.isNumericSpace(" ") = true
N.isNumericSpace("123") = true
N.isNumericSpace("12 3") = true
N.isNumericSpace("ab2c") = false
N.isNumericSpace("12-3") = false
N.isNumericSpace("12.3") = false
cs - the CharSequence to check, may be nulltrue if only contains digits or space, and is non-nullpublic static boolean isWhitespace(CharSequence cs)
Checks if the CharSequence contains only whitespace.
null or empty CharSequence (length()=0) will return false
.
N.isWhitespace(null) = false
N.isWhitespace("") = false
N.isWhitespace(" ") = true
N.isWhitespace("abc") = false
N.isWhitespace("ab2c") = false
N.isWhitespace("ab-c") = false
cs - the CharSequence to check, may be nulltrue if only contains whitespace, and is non-nullpublic static boolean isNumber(String str)
Checks whether the String a valid Java number. true is
returned if there is a number which can be initialized by
createNumber with specified String.
Null and empty String will return false.
str - the String to checktrue if the string is a correctly formatted number0Xhhh and octal 0ddd
validationpublic static boolean isAsciiDigtalNumber(String str)
true is returned if the specified str only
includes characters ('0' ~ '9', '.', '-', '+', 'e').
false is return if the specified String is null/empty, or contains empty chars.
"0" => true
" 0.1 " => false
"abc" => false
"1 a" => false
"2e10" => true
"2E-10" => truestr - public static boolean isAsciiDigtalInteger(String str)
true is returned if the specified str only
includes characters ('0' ~ '9', '-', '+' ).
false is return if the specified String is null/empty, or contains empty chars.
"-123" => true
"+123" => true
"123" => true
"+0" => true
"-0" => true
"0" => true
" 0.1 " => false
"abc" => false
"1 a" => false
"2e10" => falsestr - public static int indexOf(String str, int targetChar)
str - targetChar - public static int indexOf(String str, int fromIndex, int targetChar)
str - fromIndex - targetChar - public static int indexOf(String str, int fromIndex, String substr)
str - fromIndex - substr - @SafeVarargs public static int indexOfAny(String str, char... chs)
str - chs - @SafeVarargs public static int indexOfAny(String str, String... substrs)
str - substrs - @SafeVarargs public static int indexOfAnyBut(String str, char... chs)
str - chs - public static int indexOf(String str, String substr, String delimiter)
str - substr - delimiter - public static int indexOf(String str, int fromIndex, String substr, String delimiter)
str - fromIndex - the index from which to start the search.substr - delimiter - public static int indexOfIgnoreCase(String str, String substr)
str - substr - public static int indexOfIgnoreCase(String str, int fromIndex, String substr)
str - fromIndex - substr - public static int ordinalIndexOf(String str, String substr, int ordinal)
Finds the n-th index within a String, handling null.
str - substr - ordinal - the n-th searchStr to findN.INDEX_NOT_FOUND) if no match or null or empty
string inputpublic static int lastIndexOf(String str, int targetChar)
str - targetChar - public static int lastIndexOf(String str, int fromIndex, int targetChar)
ch in the range from 0 to 0xFFFF (inclusive),
the index returned is the largest value k such that: is true. For other values of(this.charAt(k) == ch) && (k <= fromIndex)
ch, it is the
largest value k such that: is true. In either case, if no such character occurs in this string at or before position(this.codePointAt(k) == ch) && (k <= fromIndex)
fromIndex, then
-1 is returned.
All indices are specified in char values (Unicode code
units).
str - fromIndex - the index to start the search from. There is no restriction on
the value of fromIndex. If it is greater than or
equal to the length of this string, it has the same effect as
if it were equal to one less than the length of this string:
this entire string may be searched. If it is negative, it has
the same effect as if it were -1: -1 is returned.targetChar - a character (Unicode code point).fromIndex, or -1 if the
character does not occur before that point.public static int lastIndexOf(String str, String substr)
str - substr - public static int lastIndexOf(String str, int fromIndex, String substr)
str of the last occurrence of the
specified substr, searching backward starting at the
specified index.
The returned index is the largest value k for which:
If no such value of k exists, thenk <= fromIndex && str.startsWith(substr, k)
-1 is
returned.str - fromIndex - substr - @SafeVarargs public static int lastIndexOfAny(String str, char... chs)
str - chs - @SafeVarargs public static int lastIndexOfAny(String str, String... substrs)
str - substrs - public static int lastIndexOf(String str, String substr, String delimiter)
str - substr - delimiter - public static int lastIndexOf(String str, int fromIndex, String substr, String delimiter)
str - fromIndex - the start index to traverse backwards fromsubstr - delimiter - public static int lastIndexOfIgnoreCase(String str, String substr)
str - substr - public static int lastIndexOfIgnoreCase(String str, int fromIndex, String substr)
str - fromIndex - substr - public static int lastOrdinalIndexOf(String str, String substr, int ordinal)
Finds the n-th last index within a String, handling null.
str - substr - ordinal - the n-th last searchStr to findN.INDEX_NOT_FOUND) if no match or null or empty
string inputpublic static int occurrencesOf(String str, String substr)
str - substr - N.occurrencesOf(String, String)public static boolean contains(String str, int targetChar)
str - targetChar - public static boolean contains(String str, String substr)
str - substr - public static boolean contains(String str, String substr, String delimiter)
str - substr - delimiter - public static boolean containsIgnoreCase(String str, String substr)
str - substr - @SafeVarargs public static boolean containsAny(String str, char... chs)
str - chs - @SafeVarargs public static boolean containsOnly(String str, char... chs)
str - chs - @SafeVarargs public static boolean containsNone(String str, char... chs)
str - chs - public static boolean containsWhitespace(String str)
str - public static boolean startsWith(String str, String prefix)
str - prefix - public static boolean startsWithIgnoreCase(String str, String prefix)
str - prefix - @SafeVarargs public static boolean startsWithAny(String str, String... substrs)
str - substrs - public static boolean endsWith(String str, String suffix)
str - suffix - public static boolean endsWithIgnoreCase(String str, String suffix)
str - suffix - @SafeVarargs public static boolean endsWithAny(String str, String... substrs)
str - substrs - @SafeVarargs public static boolean equalsAny(String str, String... searchStrings)
str - searchStrings - @SafeVarargs public static boolean equalsAnyIgnoreCase(String str, String... searchStrings)
str - searchStrings - public static boolean equalsIgnoreCase(String a, String b)
a - b - public static int indexOfDifference(String a, String b)
Compares two Strings, and returns the index at which the Stringss begin to differ.
For example,
indexOfDifference("i am a machine", "i am a robot") -> 7
N.indexOfDifference(null, null) = -1
N.indexOfDifference("", "") = -1
N.indexOfDifference("", "abc") = 0
N.indexOfDifference("abc", "") = 0
N.indexOfDifference("abc", "abc") = -1
N.indexOfDifference("ab", "abxyz") = 2
N.indexOfDifference("abcde", "abxyz") = 2
N.indexOfDifference("abcde", "xyz") = 0
a - the first String, may be nullb - the second String, may be null@SafeVarargs public static int indexOfDifference(String... strs)
Compares all Strings in an array and returns the index at which the Strings begin to differ.
For example,
indexOfDifference(new String[] {"i am a machine", "i am a robot"}) -> 7
N.indexOfDifference(null) = -1
N.indexOfDifference(new String[] {}) = -1
N.indexOfDifference(new String[] {"abc"}) = -1
N.indexOfDifference(new String[] {null, null}) = -1
N.indexOfDifference(new String[] {"", ""}) = -1
N.indexOfDifference(new String[] {"", null}) = -1
N.indexOfDifference(new String[] {"abc", null, null}) = 0
N.indexOfDifference(new String[] {null, null, "abc"}) = 0
N.indexOfDifference(new String[] {"", "abc"}) = 0
N.indexOfDifference(new String[] {"abc", ""}) = 0
N.indexOfDifference(new String[] {"abc", "abc"}) = -1
N.indexOfDifference(new String[] {"abc", "a"}) = 1
N.indexOfDifference(new String[] {"ab", "abxyz"}) = 2
N.indexOfDifference(new String[] {"abcde", "abxyz"}) = 2
N.indexOfDifference(new String[] {"abcde", "xyz"}) = 0
N.indexOfDifference(new String[] {"xyz", "abcde"}) = 0
N.indexOfDifference(new String[] {"i am a machine", "i am a robot"}) = 7
strs - array of Strings, entries may be nullpublic static String commonPrefix(String a, String b)
prefix such that
a.toString().startsWith(prefix) && b.toString().startsWith(prefix)
, taking care not to split surrogate pairs. If a and b
have no common prefix, returns the empty string.a - b - @SafeVarargs public static String commonPrefix(String... strs)
strs - public static String commonSuffix(String a, String b)
suffix such that
a.toString().endsWith(suffix) && b.toString().endsWith(suffix),
taking care not to split surrogate pairs. If a and b have
no common suffix, returns the empty string.a - b - @SafeVarargs public static String commonSuffix(String... strs)
strs - public static String longestCommonSubstring(String a, String b)
a - b - "" is a or b is empty or null.public static int countMatches(String str, char ch)
str - ch - public static int countMatches(String str, String substr)
str - substr - public static String substring(String str, int inclusiveBeginIndex, int exclusiveEndIndex)
null if inclusiveBeginIndex < 0 || exclusiveEndIndex < 0 || inclusiveBeginIndex > exclusiveEndIndex,
otherwise the substring with String value: str.substring(exclusiveBeginIndex, exclusiveEndIndex) is returned.str - inclusiveBeginIndex - exclusiveEndIndex - public static String substring(String str, int inclusiveBeginIndex)
null if inclusiveBeginIndex < 0,
otherwise the substring with String value: str.substring(inclusiveBeginIndex) is returned.str - inclusiveBeginIndex - substring(String, int, int)public static String substring(String str, char delimiterOfInclusiveBeginIndex)
null if N.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0,
otherwise the substring with String value: str.substring(str.indexOf(delimiterOfInclusiveBeginIndex)) is returned.str - delimiterOfInclusiveBeginIndex - inclusiveBeginIndex <- str.indexOf(delimiterOfInclusiveBeginIndex)substring(String, int)public static String substring(String str, String delimiterOfInclusiveBeginIndex)
null if N.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0,
otherwise the substring with String value: str.substring(str.indexOf(delimiterOfInclusiveBeginIndex)) is returned.str - delimiterOfInclusiveBeginIndex - inclusiveBeginIndex <- str.indexOf(delimiterOfInclusiveBeginIndex)substring(String, int)public static String substring(String str, int inclusiveBeginIndex, char delimiterOfExclusiveEndIndex)
str - inclusiveBeginIndex - delimiterOfExclusiveEndIndex - exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) if inclusiveBeginIndex >= 0substring(String, int, int)public static String substring(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex)
str - inclusiveBeginIndex - delimiterOfExclusiveEndIndex - exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) if inclusiveBeginIndex >= 0substring(String, int, int)public static String substring(String str, int inclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex)
str - inclusiveBeginIndex - funcOfExclusiveEndIndex - exclusiveEndIndex <- funcOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) if inclusiveBeginIndex >= 0substring(String, int, int)public static String substring(String str, char delimiterOfInclusiveBeginIndex, int exclusiveEndIndex)
str - delimiterOfInclusiveBeginIndex - inclusiveBeginIndex <- str.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0exclusiveEndIndex - substring(String, int, int)public static String substring(String str, String delimiterOfInclusiveBeginIndex, int exclusiveEndIndex)
str - delimiterOfInclusiveBeginIndex - inclusiveBeginIndex <- str.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0exclusiveEndIndex - substring(String, int, int)public static String substring(String str, IntUnaryOperator funcOfInclusiveBeginIndex, int exclusiveEndIndex)
str - funcOfInclusiveBeginIndex - inclusiveBeginIndex <- funcOfInclusiveBeginIndex.applyAsInt(exclusiveEndIndex)) if exclusiveEndIndex > 0exclusiveEndIndex - substring(String, int, int)public static String substringBetween(String str, int exclusiveBeginIndex, int exclusiveEndIndex)
null if exclusiveBeginIndex < 0 || exclusiveEndIndex < 0 || exclusiveBeginIndex >= exclusiveEndIndex,
otherwise the substring with String value: str.substring(exclusiveBeginIndex + 1, exclusiveEndIndex) is returned.str - exclusiveBeginIndex - exclusiveEndIndex - public static String substringBetween(String str, int exclusiveBeginIndex, char delimiterOfExclusiveEndIndex)
str - exclusiveBeginIndex - delimiterOfExclusiveEndIndex - exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, beginIndex + 1) if exclusiveBeginIndex >= 0substringBetween(String, int, int)public static String substringBetween(String str, int exclusiveBeginIndex, String delimiterOfExclusiveEndIndex)
str - exclusiveBeginIndex - delimiterOfExclusiveEndIndex - exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, beginIndex + 1) if exclusiveBeginIndex >= 0substringBetween(String, int, int)public static String substringBetween(String str, int exclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex)
str - exclusiveBeginIndex - funcOfExclusiveEndIndex - exclusiveEndIndex <- funcOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) if inclusiveBeginIndex >= 0substringBetween(String, int, int)public static String substringBetween(String str, char delimiterOfExclusiveBeginIndex, int exclusiveEndIndex)
str - delimiterOfExclusiveBeginIndex - exclusiveBeginIndex <- str.lastIndexOf(delimiterOfExclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0exclusiveEndIndex - substringBetween(String, int, int)public static String substringBetween(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex)
str - delimiterOfExclusiveBeginIndex - exclusiveBeginIndex <- str.lastIndexOf(delimiterOfExclusiveBeginIndex, exclusiveEndIndex - 1) + delimiterOfExclusiveBeginIndex.length() - 1 if exclusiveEndIndex > 0exclusiveEndIndex - substringBetween(String, int, int)public static String substringBetween(String str, IntUnaryOperator funcOfExclusiveBeginIndex, int exclusiveEndIndex)
str - funcOfExclusiveBeginIndex - exclusiveBeginIndex <- funcOfExclusiveBeginIndex.applyAsInt(exclusiveEndIndex)) if exclusiveEndIndex > 0exclusiveEndIndex - substringBetween(String, int, int)public static String substringBetween(String str, char delimiterOfExclusiveBeginIndex, char delimiterOfExclusiveEndIndex)
str - delimiterOfExclusiveBeginIndex - delimiterOfExclusiveBeginIndex - substringBetween(String, int, int)public static String substringBetween(String str, String delimiterOfExclusiveBeginIndex, String delimiterOfExclusiveEndIndex)
str - delimiterOfExclusiveBeginIndex - delimiterOfExclusiveBeginIndex - substringBetween(String, int, int)public static String substringAfter(String str, String delimiterOfExclusiveBeginIndex)
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String.str - delimiterOfExclusiveBeginIndex - public static String substringAfterLast(String str, String delimiterOfExclusiveBeginIndex)
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String.str - delimiterOfExclusiveBeginIndex - public static String substringBefore(String str, String delimiterOfExclusiveEndIndex)
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String.str - delimiterOfExclusiveEndIndex - public static String substringBeforeLast(String str, String delimiterOfExclusiveEndIndex)
delimiterOfExclusiveBeginIndex if it exists, otherwise return null String.str - delimiterOfExclusiveEndIndex - public static u.OptionalChar firstChar(String str)
findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]].str - public static u.OptionalChar lastChar(String str)
str - public static String firstChars(String str, int n)
n chars of the specified String if its length is bigger than n,
or an empty String "" if str is empty or null, or itself it's length equal to or less than n.str - n - public static String lastChars(String str, int n)
n chars of the specified String if its length is bigger than n,
or an empty String "" if str is empty or null, or itself it's length equal to or less than n.str - n - public static String join(boolean[] a)
a - public static String join(boolean[] a, char delimiter)
a - delimiter - public static String join(boolean[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(boolean[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(char[] a)
a - public static String join(char[] a, char delimiter)
a - delimiter - public static String join(char[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(char[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(byte[] a)
a - public static String join(byte[] a, char delimiter)
a - delimiter - public static String join(byte[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(byte[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(short[] a)
a - public static String join(short[] a, char delimiter)
a - delimiter - public static String join(short[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(short[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(int[] a)
a - public static String join(int[] a, char delimiter)
a - delimiter - public static String join(int[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(int[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(long[] a)
a - public static String join(long[] a, char delimiter)
a - delimiter - public static String join(long[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(long[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(float[] a)
a - public static String join(float[] a, char delimiter)
a - delimiter - public static String join(float[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(float[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(double[] a)
a - public static String join(double[] a, char delimiter)
a - delimiter - public static String join(double[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(double[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(Object[] a, int fromIndex, int toIndex, char delimiter)
a - fromIndex - toIndex - delimiter - public static String join(Object[] a, int fromIndex, int toIndex, char delimiter, boolean trim)
a - fromIndex - toIndex - delimiter - trim - public static String join(Object[] a, int fromIndex, int toIndex, String delimiter)
a - fromIndex - toIndex - delimiter - public static String join(Object[] a, int fromIndex, int toIndex, String delimiter, boolean trim)
a - fromIndex - toIndex - delimiter - trim - public static String join(Object[] a, String delimiter, String prefix, String suffix, boolean trim)
public static String join(Object[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix, boolean trim)
a - fromIndex - toIndex - delimiter - prefix - suffix - trim - public static String join(Collection<?> c)
c - public static String join(Collection<?> c, char delimiter)
c - delimiter - public static String join(Collection<?> c, String delimiter)
c - delimiter - public static String join(Collection<?> c, int fromIndex, int toIndex, char delimiter)
c - fromIndex - toIndex - delimiter - public static String join(Collection<?> c, int fromIndex, int toIndex, char delimiter, boolean trim)
c - fromIndex - toIndex - delimiter - trim - public static String join(Collection<?> c, int fromIndex, int toIndex, String delimiter)
c - fromIndex - toIndex - delimiter - public static String join(Collection<?> c, int fromIndex, int toIndex, String delimiter, boolean trim)
c - fromIndex - toIndex - delimiter - trim - public static String join(Collection<?> c, String delimiter, String prefix, String suffix)
public static String join(Collection<?> c, String delimiter, String prefix, String suffix, boolean trim)
public static String join(Collection<?> c, int fromIndex, int toIndex, String delimiter, String prefix, String suffix, boolean trim)
c - fromIndex - toIndex - delimiter - prefix - suffix - trim - public static String join(Iterator<?> iter, String delimiter, String prefix, String suffix, boolean trim)
public static String joinEntries(Map<?,?> m, char entryDelimiter)
m - entryDelimiter - public static String joinEntries(Map<?,?> m, String entryDelimiter)
m - entryDelimiter - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, char entryDelimiter)
m - fromIndex - toIndex - entryDelimiter - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, char entryDelimiter, boolean trim)
m - fromIndex - toIndex - entryDelimiter - trim - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, String entryDelimiter)
m - fromIndex - toIndex - entryDelimiter - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, String entryDelimiter, boolean trim)
m - fromIndex - toIndex - entryDelimiter - trim - public static String joinEntries(Map<?,?> m, char entryDelimiter, char keyValueDelimiter)
m - entryDelimiter - keyValueDelimiter - public static String joinEntries(Map<?,?> m, String entryDelimiter, String keyValueDelimiter)
m - entryDelimiter - keyValueDelimiter - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, char entryDelimiter, char keyValueDelimiter)
m - fromIndex - toIndex - entryDelimiter - keyValueDelimiter - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, char entryDelimiter, char keyValueDelimiter, boolean trim)
m - fromIndex - toIndex - entryDelimiter - keyValueDelimiter - trim - public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, String entryDelimiter, String keyValueDelimiter)
m - fromIndex - toIndex - entryDelimiter - keyValueDelimiter - public static String joinEntries(Map<?,?> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix)
public static String joinEntries(Map<?,?> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim)
public static String joinEntries(Map<?,?> m, int fromIndex, int toIndex, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim)
public static String concat(String a, String b, String c, String d)
a - b - c - d - public static String concat(String a, String b, String c, String d, String e)
a - b - c - d - e - public static String concat(String a, String b, String c, String d, String e, String f)
a - b - c - d - e - f - public static String concat(String a, String b, String c, String d, String e, String f, String g)
a - b - c - d - e - f - g - public static String concat(String a, String b, String c, String d, String e, String f, String g, String h)
a - b - c - d - e - f - g - h - public static String concat(String a, String b, String c, String d, String e, String f, String g, String h, String i)
a - b - c - d - e - f - g - h - i - @SafeVarargs public static String concat(String... a)
a - public static String concat(Object a, Object b)
N.toString(a) + N.toString(b).a - b - public static String concat(Object a, Object b, Object c)
a - b - c - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d)
a - b - c - d - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d, Object e)
a - b - c - d - e - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d, Object e, Object f)
a - b - c - d - e - f - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d, Object e, Object f, Object g)
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g).a - b - c - d - e - f - g - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h)
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g) + N.toString(h).a - b - c - d - e - f - g - h - concat(Object, Object)public static String concat(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h, Object i)
N.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g) + N.toString(h) + N.toString(i).a - b - c - d - e - f - g - h - i - concat(Object, Object)public static String lenientFormat(String template, Object... args)
template string with each occurrence of "%s" replaced with
the corresponding argument value from args; or, if the placeholder and argument counts
do not match, returns a best-effort form of that string. Will not throw an exception under
normal conditions.
Note: For most string-formatting needs, use String.format,
PrintWriter.format, and related methods. These support the
full range of format
specifiers, and alert you to usage errors by throwing IllegalFormatException.
In certain cases, such as outputting debugging information or constructing a message to be
used for another unchecked exception, an exception during string formatting would serve little
purpose except to supplant the real information you were trying to provide. These are the cases
this method is made for; it instead generates a best-effort string with all supplied argument
values present. This method is also useful in environments such as GWT where String.format is not available. As an example, method implementations of the Preconditions class use this formatter, for both of the reasons just discussed.
Warning: Only the exact two-character placeholder sequence "%s" is
recognized.
template - a string containing zero or more "%s" placeholder sequences. null is treated as the four-character string "null".args - the arguments to be substituted into the message template. The first argument
specified is substituted for the first occurrence of "%s" in the template, and so
forth. A null argument is converted to the four-character string "null";
non-null values are converted to strings using Object.toString().public static String reverseDelimited(String str, char delimiter)
Reverses a String that is delimited by a specific character.
The Strings between the delimiters are not reversed. Thus
java.lang.String becomes String.lang.java (if the delimiter is
'.').
N.reverseDelimited(null, *) = null
N.reverseDelimited("", *) = ""
N.reverseDelimited("a.b.c", 'x') = "a.b.c"
N.reverseDelimited("a.b.c", ".") = "c.b.a"
str - the String to reverse, may be nulldelimiter - the delimiter character to usepublic static String reverseDelimited(String str, String delimiter)
str - delimiter - public static String sort(String str)
str is not null or empty, otherwise the specified str is returned.str - public static String rotate(String str, int shift)
Rotate (circular shift) a String of shift characters.
shift > 0, right circular shift (ex : ABCDEF => FABCDE)shift < 0, left circular shift (ex : ABCDEF => BCDEFA)
StringUtil.rotate(null, *) = null
StringUtil.rotate("", *) = ""
StringUtil.rotate("abcdefg", 0) = "abcdefg"
StringUtil.rotate("abcdefg", 2) = "fgabcde"
StringUtil.rotate("abcdefg", -2) = "cdefgab"
StringUtil.rotate("abcdefg", 7) = "abcdefg"
StringUtil.rotate("abcdefg", -7) = "abcdefg"
StringUtil.rotate("abcdefg", 9) = "fgabcde"
StringUtil.rotate("abcdefg", -9) = "cdefgab"
str - the String to rotate, may be nullshift - number of time to shift (positive : right shift, negative : left shift)shift == 0,
or null if null String inputpublic static String overlay(String str, String overlay, int start, int end)
Overlays part of a String with another String.
StringUtil.overlay(null, "abc", 0, 0) = "abc"
StringUtil.overlay("", "abc", 0, 0) = "abc"
StringUtil.overlay("abcdef", null, 2, 4) = "abef"
StringUtil.overlay("abcdef", "", 2, 4) = "abef"
StringUtil.overlay("abcdef", "zzzz", 2, 4) = "abzzzzef"
str - the String to do overlaying in, may be nulloverlay - the String to overlay, may be nullstart - the position to start overlaying atend - the position to stop overlaying before"" if null String inputCopyright © 2021. All rights reserved.