Class Strings
- Direct Known Subclasses:
Strings.StringUtil
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
static final char
static final char
static final char
static final String
A String for carriage return CR ("\r").static final String
static final String
The empty String""
.static final String
A String for linefeed LF ("\n").static final String
String with value"null"
.static final String
A String for a space character. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
blankToEmpty
(String str) static void
blankToEmpty
(String[] strs) static String
blankToNull
(String str) static void
blankToNull
(String[] strs) static String
capitalize
(String str) static String
Centers a String in a larger String of sizesize
using the space character (' ').static String
Centers a String in a larger String of sizesize
.static String
Centers a String in a larger String of sizeminLength
.static String
Removes one newline from end of a String if it's there, otherwise leave it alone.static void
static String
Remove the last character from a String.static void
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
ReturnsN.toString(a) + N.toString(b)
.static String
static String
static String
static String
static String
ReturnsN.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g)
.static String
ReturnsN.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
ReturnsN.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
static String
Returnsa + b
.static String
static String
static String
static String
static String
static String
static String
static boolean
static boolean
static boolean
static boolean
containsAny
(String str, char... chs) static boolean
containsAny
(String str, String... searchStrs) static boolean
containsAnyIgnoreCase
(String str, String... searchStrs) 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 String[]
copyThenStrip
(String[] strs) static String[]
copyThenTrim
(String[] strs) static int
countMatches
(String str, char ch) static int
countMatches
(String str, String substr) static <T extends CharSequence>
TdefaultIfBlank
(T str, Supplier<? extends T> getterForDefaultStr) static <T extends CharSequence>
TdefaultIfBlank
(T str, T defaultStr) Same asN.defaultIfBlank(CharSequence, CharSequence)
.static <T extends CharSequence>
TdefaultIfEmpty
(T str, Supplier<? extends T> getterForDefaultStr) static <T extends CharSequence>
TdefaultIfEmpty
(T str, T defaultStr) Same asN.defaultIfNullOrEmpty(CharSequence, CharSequence)
.static String
deleteWhitespace
(String str) Deletes all white spaces from a String as defined byCharacter.isWhitespace(char)
.static void
deleteWhitespace
(String[] strs) static String
emptyToNull
(String str) static void
emptyToNull
(String[] strs) static boolean
static boolean
endsWithAny
(String str, String... substrs) Ends with any.static boolean
endsWithAnyIgnoreCase
(String str, String... substrs) Ends with ignore case.static boolean
endsWithIgnoreCase
(String str, String suffix) Ends with ignore case.static boolean
static boolean
Equals with any.static boolean
equalsAnyIgnoreCase
(String str, String... searchStrs) Equals with any.static boolean
equalsIgnoreCase
(String a, String b) Equals ignore case.findAllIndicesBetween
(String str, char prefix, char postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.findAllIndicesBetween
(String str, int fromIndex, int toIndex, char prefix, char postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.findAllIndicesBetween
(String str, int fromIndex, int toIndex, String prefix, String postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.findAllIndicesBetween
(String str, String prefix, String postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.findAllSubstringsBetween
(String str, char prefix, char postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.findAllSubstringsBetween
(String str, int fromIndex, int toIndex, char prefix, char postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.findAllSubstringsBetween
(String str, int fromIndex, int toIndex, String prefix, String postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.findAllSubstringsBetween
(String str, String prefix, String postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.static u.OptionalChar
static String
firstChars
(String str, int n) Returns at most firstn
chars of the specifiedString
if its length is bigger thann
, or an empty String""
ifstr
is empty or null, or itself it's length equal to or less thann
.static <T extends CharSequence>
TfirstNonBlank
(Collection<? extends T> css) static <T extends CharSequence>
TfirstNonBlank
(T... css) static <T extends CharSequence>
TfirstNonBlank
(T a, T b) static <T extends CharSequence>
TfirstNonBlank
(T a, T b, T c) static <T extends CharSequence>
TfirstNonEmpty
(Collection<? extends T> css) static <T extends CharSequence>
TfirstNonEmpty
(T... css) Returns the first value in the array which is not empty.static <T extends CharSequence>
TfirstNonEmpty
(T a, T b) static <T extends CharSequence>
TfirstNonEmpty
(T a, T b, T c) static int
static int
static int
static int
static int
static int
static int
indexOfAny
(String str, char... chs) static int
indexOfAny
(String str, int fromIndex, char... chs) static int
indexOfAny
(String str, int fromIndex, String... substrs) static int
indexOfAny
(String str, String... substrs) static int
indexOfAnyBut
(String str, char... chs) Index of any but.static int
indexOfAnyBut
(String str, int fromIndex, char... chs) 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
static boolean
isAllBlank
(CharSequence a, CharSequence b, CharSequence c) static boolean
isAllBlank
(Collection<? extends CharSequence> css) static boolean
isAllEmpty
(CharSequence... css) Checks if all of the CharSequences are empty ("") or null.static boolean
static boolean
isAllEmpty
(CharSequence a, CharSequence b, CharSequence c) static boolean
isAllEmpty
(Collection<? extends CharSequence> css) static boolean
Checks if is all lower case.static boolean
Checks if is all upper case.static boolean
isAlpha
(CharSequence cs) Checks if the CharSequence contains only Unicode letters.static boolean
Checks if the CharSequence contains only Unicode letters or digits.static boolean
Checks if the CharSequence contains only Unicode letters, digits or space (' '
).static boolean
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
static boolean
isAnyBlank
(CharSequence a, CharSequence b, CharSequence c) static boolean
isAnyBlank
(Collection<? extends CharSequence> css) static boolean
isAnyEmpty
(CharSequence... css) Checks if any of the CharSequences are empty ("") or null.static boolean
static boolean
isAnyEmpty
(CharSequence a, CharSequence b, CharSequence c) static boolean
isAnyEmpty
(Collection<? extends CharSequence> css) 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
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
Checks if is ascii alphanumeric.static boolean
Checks if is ascii alphanumeric space.static boolean
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
true
is returned if the specifiedstr
only includes characters ('0' ~ '9', '-', '+' ).static boolean
true
is returned if the specifiedstr
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
Checks if is ascii numeric.static boolean
isAsciiPrintable
(char ch) Checks whether the character is ASCII 7 bit printable.static boolean
Checks if is ascii printable.static boolean
isAsciiUpperCase
(char ch) Checks if is ascii upper case.static boolean
isBlank
(CharSequence cs) Same asN.isBlank(CharSequence)
.static boolean
isDigit
(char ch) Checks if is digit.static boolean
isEmpty
(CharSequence cs) Same asN.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
Copied from Apache Commons Lang: StringUtils#isMixedCase.static boolean
Same asN.notBlank(CharSequence)
.static boolean
Same asN.notNullOrEmpty(CharSequence)
.static boolean
Deprecated.static boolean
Checks if the CharSequence contains only Unicode digits.static boolean
Checks if the CharSequence contains only Unicode digits or space (' '
).static boolean
isUpperCase
(char ch) Checks if is upper case.static boolean
static boolean
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
static String
static String
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
static String
static String
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
static String
static String
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
static String
static String
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
static String
static String
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
static String
static String
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
static String
static String
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
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
static String
join
(Object[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix, boolean trim) static String
static String
static String
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
static String
static String
static String
static String
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) joinEntries
(Map<K, V> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim, Throwables.Function<? super K, ?, E> keyMapper, Throwables.Function<? super V, ?, E2> valueMapper) static int
largestIndexOfAll
(String str, String... substrs) Last index of any.static u.OptionalChar
static String
Returns at most lastn
chars of the specifiedString
if its length is bigger thann
, or an empty String""
ifstr
is empty or null, or itself it's length equal to or less thann
.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 withinstr
of the last occurrence of the specifiedsubstr
, 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, handlingnull
.static String
lenientFormat
(String template, Object... args) Copied from Google Guava
Returns the giventemplate
string with each occurrence of"%s"
replaced by the corresponding argument value fromargs
; or, if the placeholder and argument counts do not match, returns a best-effort form of that string.static String
static String
normalizeSpace
(String str) static String
nullToEmpty
(String str) static void
nullToEmpty
(String[] strs) static int
occurrencesOf
(String str, char ch) static int
occurrencesOf
(String str, String substr) static int
ordinalIndexOf
(String str, String substr, int ordinal) Finds the n-th index within a String, handlingnull
.static String
Overlays part of a String with another String.static String
static String
static String
static String
static String
static String
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
quoteEscaped
(String str, char quoteChar) static String
Removes all occurrences of a character from within the source string.static String
Removes the all.static String
Removes the all.static String
Removes all occurrences of a substring from within the source string.static String
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
static String
static String
static String
Replaces a String with another String inside a larger String, for the firstmax
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
replaceFirst
(String str, int fromIndex, String target, String replacement) static String
replaceFirst
(String str, String target, String replacement) Replaces a String with another String inside a larger String, once.static String
replaceFirstIgnoreCase
(String str, int fromIndex, String target, String replacement) Replace once ignore case.static String
replaceFirstIgnoreCase
(String str, String target, String replacement) Replace once 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) Deprecated.UsereplaceFirst(String,int,String,String)
insteadstatic String
replaceOnce
(String str, String target, String replacement) Deprecated.UsereplaceFirst(String,String,String)
insteadstatic String
replaceOnceIgnoreCase
(String str, int fromIndex, String target, String replacement) Deprecated.UsereplaceFirstIgnoreCase(String,int,String,String)
insteadstatic String
replaceOnceIgnoreCase
(String str, String target, String replacement) Deprecated.UsereplaceFirstIgnoreCase(String,String,String)
insteadstatic 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 thePattern.DOTALL
option.static String
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 (circular shift) a String ofshift
characters.static String
static String
static int
smallestIndexOfAll
(String str, int fromIndex, String... substrs) Find the first index of any of a set of potential substrings fromfromIndex
.static int
smallestIndexOfAll
(String str, String... substrs) Find the first index of any of a set of potential substrings.static String
Returns a new sorted String if the specifiedstr
is not null or empty, otherwise the specifiedstr
is returned.static String[]
static String[]
static String[]
static String[]
static String[]
Deprecated.Splitter
is recommended.static String[]
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
startsWithAnyIgnoreCase
(String str, String... substrs) Starts with any.static boolean
startsWithIgnoreCase
(String str, String prefix) Starts with ignore case.static String
Strips whitespace from the start and end of a String.static void
static void
static String
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
static String
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 ifnull
input.static void
stripToEmpty
(String[] strs) static String
stripToNull
(String str) Strips whitespace from the start and end of a String returningnull
if the String is empty ("") after the strip.static void
stripToNull
(String[] strs) static String
Returnsnull
ifN.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0
, otherwise thesubstring
with String value:str.substring(str.indexOf(delimiterOfInclusiveBeginIndex))
is returned.static String
Returnsnull
if(str == null || str.length() == 0 || exclusiveEndIndex <= 0)
, orstr.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) < 0
.static String
Returnsnull
ifinclusiveBeginIndex < 0
, otherwise thesubstring
with String value:str.substring(inclusiveBeginIndex)
is returned.static String
Returnsnull
ifstr == null || str.length() == 0 || inclusiveBeginIndex < 0
.static String
Returnsnull
ifinclusiveBeginIndex < 0 ||exclusiveEndIndex <= 0 || inclusiveBeginIndex > exclusiveEndIndex
, otherwise thesubstring
with String value:str.substring(exclusiveBeginIndex, exclusiveEndIndex)
is returned.static String
Returnsnull
if(str == null || inclusiveBeginIndex < 0 || delimiterOfExclusiveEndIndex == null)
, orstr.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) < 0
.static String
substring
(String str, int inclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex) Returnsnull
if(str == null || inclusiveBeginIndex < 0)
, orfuncOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) < 0
.static String
Returnsnull
ifN.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0
, otherwise thesubstring
with String value:str.substring(str.indexOf(delimiterOfInclusiveBeginIndex))
is returned.static String
Returnsnull
if(str == null || delimiterOfInclusiveBeginIndex == null ||exclusiveEndIndex <= 0)
, orstr.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) < 0
.static String
substring
(String str, IntUnaryOperator funcOfInclusiveBeginIndex, int exclusiveEndIndex) Returnsnull
if(str == null ||exclusiveEndIndex <= 0)
, orfuncOfInclusiveBeginIndex.applyAsInt(exclusiveEndIndex) < 0
.static String
substringAfter
(String str, char delimiterOfExclusiveBeginIndex) Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfter
(String str, String delimiterOfExclusiveBeginIndex) Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfter
(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfterAny
(String str, char... delimitersOfExclusiveBeginIndex) Returns the substring before any ofdelimitersOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfterAny
(String str, String... delimitersOfExclusiveBeginIndex) Returns the substring before any ofdelimitersOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfterLast
(String str, char delimiterOfExclusiveBeginIndex) Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfterLast
(String str, String delimiterOfExclusiveBeginIndex) Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringAfterLast
(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBefore
(String str, char delimiterOfExclusiveEndIndex) Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBefore
(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex) Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBefore
(String str, String delimiterOfExclusiveEndIndex) Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBeforeAny
(String str, char... delimitersOfExclusiveEndIndex) Returns the substring before any ofdelimitersOfExclusiveEndIndex
if it exists, otherwise returnnull
String.static String
substringBeforeAny
(String str, String... delimitersOfExclusiveEndIndex) Returns the substring before any ofdelimitersOfExclusiveEndIndex
if it exists, otherwise returnnull
String.static String
substringBeforeLast
(String str, char delimiterOfExclusiveEndIndex) Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBeforeLast
(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex) Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.static String
substringBeforeLast
(String str, String delimiterOfExclusiveEndIndex) Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
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) Returnsnull
ifexclusiveBeginIndex < 0 ||exclusiveEndIndex <= 0 || exclusiveBeginIndex >= exclusiveEndIndex
, otherwise thesubstring
with String value:str.substring(exclusiveBeginIndex + 1, exclusiveEndIndex)
is returned.static String
substringBetween
(String str, int exclusiveBeginIndex, String delimiterOfExclusiveEndIndex) static String
substringBetween
(String str, int fromIndex, String delimiterOfExclusiveBeginIndex, String delimiterOfExclusiveEndIndex) static String
substringBetween
(String str, int exclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex) static String
substringBetween
(String str, String tag) static String
substringBetween
(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) static String
substringBetween
(String str, String delimiterOfExclusiveBeginIndex, String delimiterOfExclusiveEndIndex) static String
substringBetween
(String str, IntUnaryOperator funcOfExclusiveBeginIndex, int exclusiveEndIndex) static char
swapCase
(char ch) static String
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 aCharSequence
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 perString.toLowerCase()
.static String
toLowerCase
(String str, Locale locale) Converts a String to lower case as perString.toLowerCase(Locale)
.static String
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 perString.toUpperCase()
.static String
toUpperCase
(String str, Locale locale) Converts a String to upper case as perString.toUpperCase(Locale)
.static String
To upper case with underscore.static String
Removes control characters (char <= 32) from both ends of this String, handlingnull
by returningnull
.static void
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 isnull
.static void
trimToEmpty
(String[] strs) static String
trimToNull
(String str) Removes control characters (char <= 32) from both ends of this String returningnull
if the String is empty ("") after the trim or if it isnull
.static void
trimToNull
(String[] strs) static String
Truncates a String.static String
Truncates a String.static String
uncapitalize
(String str) static String
unicodeEscaped
(char ch) Converts the char to the unicode format ' '.static String
static String
Unwraps the specified stringstr
if and only if it's wrapped by the specifiedprefix
andsuffix
static String
valueOf
(char[] value) Returns the string representation of thechar
array or null.static String
static String
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"
-
Field Details
-
NULL_STRING
String with value"null"
. -
EMPTY_STRING
The empty String""
. -
SPACE
A String for a space character.- Since:
- 3.2
- See Also:
-
LF
A String for linefeed LF ("\n").- Since:
- 3.2
- See Also:
-
CR
A String for carriage return CR ("\r").- Since:
- 3.2
- See Also:
-
CHAR_ZERO
- See Also:
-
CHAR_SPACE
-
CHAR_LF
-
CHAR_CR
-
ELEMENT_SEPARATOR
-
-
Method Details
-
valueOf
Returns the string representation of thechar
array or null.- Parameters:
value
- the character array.- Returns:
- a String or null
- Since:
- 3.9
- See Also:
-
String.valueOf(char[])
CommonUtil.toString(Object)
-
isValidJavaIdentifier
- Parameters:
str
-- Returns:
-
isEmpty
Same asN.isNullOrEmpty(CharSequence)
.- Parameters:
cs
-- Returns:
- See Also:
-
CommonUtil.isNullOrEmpty(CharSequence)
-
isBlank
Same asN.isBlank(CharSequence)
.- Parameters:
cs
-- Returns:
- See Also:
-
CommonUtil.isBlank(CharSequence)
-
isNotEmpty
Same asN.notNullOrEmpty(CharSequence)
.- Parameters:
cs
-- Returns:
- See Also:
-
CommonUtil.notNullOrEmpty(CharSequence)
-
isNotBlank
Same asN.notBlank(CharSequence)
.- Parameters:
cs
-- Returns:
- See Also:
-
CommonUtil.notBlank(CharSequence)
-
isAllEmpty
-
isAllEmpty
-
isAllEmpty
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
- Parameters:
css
- the CharSequences to check, may be null or empty- Returns:
true
if all of the CharSequences are empty or null- Since:
- 3.6
- See Also:
-
CommonUtil.allNullOrEmpty(CharSequence...)
-
isAllEmpty
- Parameters:
css
-- Returns:
- See Also:
-
CommonUtil.allNullOrEmpty(Collection)
-
isAllBlank
-
isAllBlank
-
isAllBlank
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
- Parameters:
css
- the CharSequences to check, may be null or empty- Returns:
true
if all of the CharSequences are empty or null or whitespace only- Since:
- 3.6
- See Also:
-
CommonUtil.allBlank(CharSequence...)
-
isAllBlank
- Parameters:
css
-- Returns:
- See Also:
-
CommonUtil.allBlank(Collection)
-
isAnyEmpty
-
isAnyEmpty
-
isAnyEmpty
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
- Parameters:
css
- the CharSequences to check, may be null or empty- Returns:
true
if any of the CharSequences are empty or null- Since:
- 3.2
- See Also:
-
CommonUtil.anyNullOrEmpty(CharSequence...)
-
isAnyEmpty
- Parameters:
css
-- Returns:
- See Also:
-
CommonUtil.anyNullOrEmpty(CharSequence...)
-
isAnyBlank
-
isAnyBlank
-
isAnyBlank
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
- Parameters:
css
- the CharSequences to check, may be null or empty- Returns:
true
if any of the CharSequences are empty or null or whitespace only- Since:
- 3.2
- See Also:
-
CommonUtil.anyBlank(CharSequence...)
-
isAnyBlank
- Parameters:
css
-- Returns:
- See Also:
-
CommonUtil.anyBlank(Collection)
-
firstNonEmpty
- Type Parameters:
T
-- Parameters:
a
-b
-- Returns:
- the first value from specified parameters which is not empty, or
null
if there are no non-empty values - See Also:
-
firstNonEmpty
- Type Parameters:
T
-- Parameters:
a
-b
-c
-- Returns:
- the first value from specified parameters which is not empty, or
null
if there are no non-empty values - See Also:
-
firstNonEmpty
Returns the first value in the array which is not empty.
If all values are empty or the array is
null
or empty thennull
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
- Type Parameters:
T
- the specific kind of CharSequence- Parameters:
css
- the values to test, may benull
or empty- Returns:
- the first value from
css
which is not empty, ornull
if there is no non-empty value. - Since:
- 3.8
- See Also:
-
CommonUtil.firstNonEmpty(CharSequence...)
-
firstNonEmpty
- Type Parameters:
T
-- Parameters:
css
-- Returns:
- the first value from
css
which is not empty, ornull
if there is no non-empty value. - See Also:
-
CommonUtil.firstNonEmpty(CharSequence...)
-
firstNonBlank
- Type Parameters:
T
-- Parameters:
a
-b
-- Returns:
- the first value from specified parameters which is not blank, or
null
if there are no non-blank values - See Also:
-
firstNonBlank
- Type Parameters:
T
-- Parameters:
a
-b
-c
-- Returns:
- the first value from specified parameters which is not blank, or
null
if there are no non-blank values - See Also:
-
firstNonBlank
- Type Parameters:
T
-- Parameters:
css
-- Returns:
- the first value from
css
which is not empty, ornull
if there is no non-blank value. - See Also:
-
CommonUtil.firstNonBlank(CharSequence...)
-
firstNonBlank
- Type Parameters:
T
-- Parameters:
css
-- Returns:
- the first value from
css
which is not empty, ornull
if there is no non-blank value. - See Also:
-
CommonUtil.firstNonEmpty(CharSequence...)
-
defaultIfEmpty
Same asN.defaultIfNullOrEmpty(CharSequence, CharSequence)
.- Type Parameters:
T
-- Parameters:
str
-defaultStr
-- Returns:
- See Also:
-
CommonUtil.defaultIfNullOrEmpty(CharSequence, CharSequence)
-
defaultIfEmpty
public static <T extends CharSequence> T defaultIfEmpty(T str, Supplier<? extends T> getterForDefaultStr) - Type Parameters:
T
-- Parameters:
str
-getterForDefaultStr
-- Returns:
-
defaultIfBlank
Same asN.defaultIfBlank(CharSequence, CharSequence)
.- Type Parameters:
T
-- Parameters:
str
-defaultStr
-- Returns:
- See Also:
-
CommonUtil.defaultIfBlank(CharSequence, CharSequence)
-
defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(T str, Supplier<? extends T> getterForDefaultStr) - Type Parameters:
T
-- Parameters:
str
-getterForDefaultStr
-- Returns:
-
nullToEmpty
- Parameters:
str
-- Returns:
-
nullToEmpty
- Parameters:
strs
-
-
emptyToNull
- Parameters:
str
-- Returns:
-
emptyToNull
- Parameters:
strs
-
-
blankToEmpty
- Parameters:
str
-- Returns:
-
blankToEmpty
- Parameters:
strs
-
-
blankToNull
- Parameters:
str
-- Returns:
-
blankToNull
- Parameters:
strs
-
-
abbreviate
Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."
Specifically:
- If the number of characters in
str
is less than or equal tomaxWidth
, returnstr
. - Else abbreviate it to
(substring(str, 0, max-3) + "...")
. - If
maxWidth
is less than4
, throw anIllegalArgumentException
. - In no case will it return a String of length greater than
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
- Parameters:
str
- the String to check, may be nullmaxWidth
- maximum length of result String, must be at least 4- Returns:
- abbreviated String
- Throws:
IllegalArgumentException
- if the width is too small- Since:
- 2.0
- If the number of characters in
-
abbreviate
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:
- If the number of characters in
str
is less than or equal tomaxWidth
, returnstr
. - Else abbreviate it to
(substring(str, 0, max-abbrevMarker.length) + abbrevMarker)
. - If
maxWidth
is less thanabbrevMarker.length + 1
, throw anIllegalArgumentException
. - In no case will it return a String of length greater than
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
- Parameters:
str
- the String to check, may be nullabbrevMarker
- the String used as replacement markermaxWidth
- maximum length of result String, must be at leastabbrevMarker.length + 1
- Returns:
- abbreviated String
- Throws:
IllegalArgumentException
- if the width is too small- Since:
- 3.6
- If the number of characters in
-
abbreviateMiddle
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:
- Neither the String for abbreviation nor the replacement String are null or empty
- The length to truncate to is less than the length of the supplied String
- The length to truncate to is greater than 0
- The abbreviated String will have enough room for the length supplied replacement String and the first and last characters of the supplied String for abbreviation
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"
- Parameters:
str
- the String to abbreviate, may be nullmiddle
- the String to replace the middle characters with, may be nulllength
- the length to abbreviatestr
to.- Returns:
- the abbreviated String if the above criteria is met, or the original String supplied for abbreviation.
- Since:
- 2.5
-
center
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 "
- Parameters:
str
- the String to center, may be nullsize
- the int size of new String- Returns:
- centered String
-
center
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"
- Parameters:
str
- the String to center, may be nullsize
- the int size of new String.padChar
- the character to pad the new String with- Returns:
- centered String
- Since:
- 2.0
-
center
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 "
- Parameters:
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 empty- Returns:
- centered String
-
padStart
- Parameters:
str
-minLength
-- Returns:
-
padStart
- Parameters:
str
-minLength
-padChar
-- Returns:
-
padStart
- Parameters:
str
-minLength
-padStr
-- Returns:
-
padEnd
- Parameters:
str
-minLength
-- Returns:
-
padEnd
- Parameters:
str
-minLength
-padChar
-- Returns:
-
padEnd
- Parameters:
str
-minLength
-padStr
-- Returns:
-
repeat
- Parameters:
ch
-n
-- Returns:
-
repeat
- Parameters:
ch
-n
-delimiter
-- Returns:
-
repeat
- Parameters:
str
-repeat
-- Returns:
-
repeat
- Parameters:
str
-n
-delimiter
-- Returns:
-
repeat
- Parameters:
str
-n
-delimiter
-prefix
-suffix
-- Returns:
-
toLowerCase
public static char toLowerCase(char ch) To lower case.- Parameters:
ch
-- Returns:
-
toLowerCase
Converts a String to lower case as per
String.toLowerCase()
.A
null
input String returnsnull
.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 methodtoLowerCase(String, Locale)
should be used with a specific locale (e.g.Locale.ENGLISH
).- Parameters:
str
- the String to lower case, may be null- Returns:
-
toLowerCase
Converts a String to lower case as per
String.toLowerCase(Locale)
.A
null
input String returnsnull
.StringUtil.toLowerCase(null, Locale.ENGLISH) = null StringUtil.toLowerCase("", Locale.ENGLISH) = "" StringUtil.toLowerCase("aBc", Locale.ENGLISH) = "abc"
- Parameters:
str
- the String to lower case, may be nulllocale
- the locale that defines the case transformation rules, must not be null- Returns:
- Since:
- 2.5
-
toLowerCaseWithUnderscore
To lower case with underscore.- Parameters:
str
-- Returns:
-
toUpperCase
public static char toUpperCase(char ch) To upper case.- Parameters:
ch
-- Returns:
-
toUpperCase
Converts a String to upper case as per
String.toUpperCase()
.A
null
input String returnsnull
.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 methodtoLowerCase(String, Locale)
should be used with a specific locale (e.g.Locale.ENGLISH
).- Parameters:
str
- the String to upper case, may be null- Returns:
-
toUpperCase
Converts a String to upper case as per
String.toUpperCase(Locale)
.A
null
input String returnsnull
.N.toUpperCase(null, Locale.ENGLISH) = null N.toUpperCase("", Locale.ENGLISH) = "" N.toUpperCase("aBc", Locale.ENGLISH) = "ABC"
- Parameters:
str
- the String to upper case, may be nulllocale
- the locale that defines the case transformation rules, must not be null- Returns:
- Since:
- 2.5
-
toUpperCaseWithUnderscore
To upper case with underscore.- Parameters:
str
-- Returns:
-
toCamelCase
- Parameters:
str
-- Returns:
-
toCharArray
- Parameters:
source
-- Returns:
-
toCodePoints
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
- Parameters:
str
- the character sequence to convert- Returns:
- an empty array is the specified String
str
is null or empty. - Since:
- 3.6
-
swapCase
public static char swapCase(char ch) - Parameters:
ch
-- Returns:
-
swapCase
Swaps the case of a String changing upper and title case to lower case, and lower case to upper case.
- Upper case character converts to Lower case
- Title case character converts to Lower case
- Lower case character converts to Upper case
For a word based algorithm, see
WordUtils.swapCase(String)
. Anull
input String returnsnull
.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.
- Parameters:
str
- the String to swap case, may be null- Returns:
-
capitalize
- Parameters:
str
-- Returns:
-
uncapitalize
- Parameters:
str
-- Returns:
-
quoteEscaped
Replace ''' or '"' with '\'' or '\"' if the previous char of the quotation is not '\'. original String is returned if the specified String isnull
or empty.- Parameters:
str
-- Returns:
-
quoteEscaped
- Parameters:
str
-quoteChar
- it should be"
or'
.- Returns:
-
unicodeEscaped
Converts the char to the unicode format ' '.
This format is the Java source code format.
StringUtil.unicodeEscaped(' ') = " " StringUtil.unicodeEscaped('A') = "A"
- Parameters:
ch
- the character to convert- Returns:
-
normalizeSpace
Similar to http://www.w3.org/TR/xpath/#function-normalize -space
The function returns the argument string with whitespace normalized by using
In XML Whitespace characters are the same as those allowed by the S production, which is S ::= (#x20 | #x9 | #xD | #xA)+
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:
- \x0B = vertical tab
- \f = #xC = form feed
- #x20 = space
- #x9 = \t
- #xA = \n
- #xD = \r
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)
- Parameters:
str
- the source String to normalize whitespaces from, may be null- Returns:
- null String input
- Since:
- 3.0
- See Also:
-
replaceAll
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"
- Parameters:
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- Returns:
- String input
- See Also:
-
#replaceAll(String text, String searchString, String replacement, int max)
-
replaceAll
- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replaceFirst
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"
- Parameters:
str
-target
-replacement
- the String to replace with, may be null- Returns:
- the text with any replacements processed,
null
if null String input - See Also:
-
#replace(String text, String searchString, String replacement, int max)
-
replaceFirst
- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replaceOnce
Deprecated.UsereplaceFirst(String,String,String)
insteadReplaces 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"
- Parameters:
str
-target
-replacement
- the String to replace with, may be null- Returns:
- the text with any replacements processed,
null
if null String input - See Also:
-
#replace(String text, String searchString, String replacement, int max)
-
replaceOnce
@Deprecated public static String replaceOnce(String str, int fromIndex, String target, String replacement) Deprecated.UsereplaceFirst(String,int,String,String)
instead- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replace
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"
- Parameters:
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 maximum- Returns:
- String input
-
replaceAllIgnoreCase
Replace all ignore case.- Parameters:
str
-target
-replacement
-- Returns:
-
replaceAllIgnoreCase
public static String replaceAllIgnoreCase(String str, int fromIndex, String target, String replacement) Replace all ignore case.- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replaceFirstIgnoreCase
Replace once ignore case.- Parameters:
str
-target
-replacement
-- Returns:
-
replaceFirstIgnoreCase
public static String replaceFirstIgnoreCase(String str, int fromIndex, String target, String replacement) Replace once ignore case.- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replaceOnceIgnoreCase
@Deprecated public static String replaceOnceIgnoreCase(String str, String target, String replacement) Deprecated.UsereplaceFirstIgnoreCase(String,String,String)
insteadReplace once ignore case.- Parameters:
str
-target
-replacement
-- Returns:
-
replaceOnceIgnoreCase
@Deprecated public static String replaceOnceIgnoreCase(String str, int fromIndex, String target, String replacement) Deprecated.UsereplaceFirstIgnoreCase(String,int,String,String)
insteadReplace once ignore case.- Parameters:
str
-fromIndex
-target
-replacement
-- Returns:
-
replaceIgnoreCase
public static String replaceIgnoreCase(String str, int fromIndex, String target, String replacement, int max) Replace ignore case.- Parameters:
str
-fromIndex
-target
-replacement
-max
-- Returns:
-
replacePattern
Replaces each substring of the source String that matches the given regular expression with the given replacement using thePattern.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)
- Parameters:
source
- the source stringregex
- the regular expression to which this string is to be matchedreplacement
- the string to be substituted for each match- Returns:
- The resulting
String
- Since:
- 3.2
- See Also:
-
removeStart
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A
null
source string will returnnull
. An empty ("") source string will return the empty string. Anull
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"
- Parameters:
str
- the source String to search, may be nullremoveStr
- the String to search for and remove, may be null- Returns:
- null String input
- Since:
- 2.1
-
removeStartIgnoreCase
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 returnnull
. An empty ("") source string will return the empty string. Anull
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"
- Parameters:
str
- the source String to search, may be nullremoveStr
- the String to search for (case insensitive) and remove, may be null- Returns:
- null String input
- Since:
- 2.4
-
removeEnd
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A
null
source string will returnnull
. An empty ("") source string will return the empty string. Anull
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"
- Parameters:
str
- the source String to search, may be nullremoveStr
- the String to search for and remove, may be null- Returns:
- null String input
- Since:
- 2.1
-
removeEndIgnoreCase
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 returnnull
. An empty ("") source string will return the empty string. Anull
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")
- Parameters:
str
- the source String to search, may be nullremoveStr
- the String to search for (case insensitive) and remove, may be null- Returns:
- null String input
- Since:
- 2.4
-
removeAll
Removes all occurrences of a character from within the source string.
A
null
source string will returnnull
. 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"
- Parameters:
str
- the source String to search, may be nullremoveChar
- the char to search for and remove, may be null- Returns:
- null String input
- Since:
- 2.1
-
removeAll
Removes the all.- Parameters:
str
-fromIndex
-removeChar
-- Returns:
-
removeAll
Removes all occurrences of a substring from within the source string.
A
null
source string will returnnull
. An empty ("") source string will return the empty string. Anull
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"
- Parameters:
str
- the source String to search, may be nullremoveStr
- the String to search for and remove, may be null- Returns:
- null String input
- Since:
- 2.1
-
removeAll
Removes the all.- Parameters:
str
-fromIndex
-removeStr
-- Returns:
-
removePattern
Removes each substring of the source String that matches the given regular expression using the DOTALL option.- Parameters:
source
- the source stringregex
- the regular expression to which this string is to be matched- Returns:
- The resulting
String
- Since:
- 3.2
- See Also:
-
split
- Parameters:
str
-delimiter
-- Returns:
-
split
- Parameters:
str
-delimiter
-trim
-- Returns:
-
split
- Parameters:
str
-delimiter
-- Returns:
-
split
- Parameters:
str
-delimiter
-trim
-- Returns:
-
split
Deprecated.Splitter
is recommended.- Parameters:
str
-delimiter
-max
-- Returns:
-
split
Deprecated.Splitter
is recommended.- Parameters:
str
-delimiter
-max
-trim
-- Returns:
-
splitPreserveAllTokens
Split preserve all tokens.- Parameters:
str
-delimiter
-- Returns:
-
splitPreserveAllTokens
Split preserve all tokens.- Parameters:
str
-delimiter
-trim
-- Returns:
-
splitPreserveAllTokens
Split preserve all tokens.- Parameters:
str
-delimiter
-- Returns:
-
splitPreserveAllTokens
Split preserve all tokens.- Parameters:
str
-delimiter
-trim
-- Returns:
-
splitPreserveAllTokens
Deprecated.Splitter
is recommended.Split preserve all tokens.- Parameters:
str
-delimiter
-max
-- Returns:
-
splitPreserveAllTokens
@Deprecated public static String[] splitPreserveAllTokens(String str, String delimiter, int max, boolean trim) Deprecated.Splitter
is recommended.Split preserve all tokens.- Parameters:
str
-delimiter
-max
-trim
-- Returns:
-
trim
Removes control characters (char <= 32) from both ends of this String, handling
null
by returningnull
.The String is trimmed using
String.trim()
. Trim removes start and end characters <= 32. To strip whitespace usestrip(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"
- Parameters:
str
- the String to be trimmed, may be null- Returns:
-
trim
- Parameters:
strs
-
-
trimToNull
Removes control characters (char <= 32) from both ends of this String returning
null
if the String is empty ("") after the trim or if it isnull
.The String is trimmed using
String.trim()
. Trim removes start and end characters <= 32. To strip whitespace usestripToNull(String)
.N.trimToNull(null) = null N.trimToNull("") = null N.trimToNull(" ") = null N.trimToNull("abc") = "abc" N.trimToNull(" abc ") = "abc"
- Parameters:
str
- the String to be trimmed, may be null- Returns:
- null String input
- Since:
- 2.0
-
trimToNull
- Parameters:
strs
-
-
trimToEmpty
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 usestripToEmpty(String)
.N.trimToEmpty(null) = "" N.trimToEmpty("") = "" N.trimToEmpty(" ") = "" N.trimToEmpty("abc") = "abc" N.trimToEmpty(" abc ") = "abc"
- Parameters:
str
- the String to be trimmed, may be null- Returns:
- Since:
- 2.0
-
trimToEmpty
- Parameters:
strs
-
-
strip
Strips whitespace from the start and end of a String.
This is similar to
trim(String)
but removes whitespace. Whitespace is defined byCharacter.isWhitespace(char)
.A
null
input String returnsnull
.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"
- Parameters:
str
- the String to remove whitespace from, may be null- Returns:
-
strip
- Parameters:
strs
-
-
stripToNull
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 byCharacter.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"
- Parameters:
str
- the String to be stripped, may be null- Returns:
- String input
- Since:
- 2.0
-
stripToNull
- Parameters:
strs
-
-
stripToEmpty
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 byCharacter.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"
- Parameters:
str
- the String to be stripped, may be null- Returns:
- Since:
- 2.0
-
stripToEmpty
- Parameters:
strs
-
-
strip
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 returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.isWhitespace(char)
. Alternatively usestrip(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"
- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespace- Returns:
-
strip
- Parameters:
strs
-stripChars
-
-
stripStart
Strips any of a set of characters from the start of a String.
A
null
input String returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.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 "
- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the characters to remove, null treated as whitespace- Returns:
-
stripStart
- Parameters:
strs
-stripChars
-
-
stripEnd
Strips any of a set of characters from the end of a String.
A
null
input String returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.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"
- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the set of characters to remove, null treated as whitespace- Returns:
-
stripEnd
- Parameters:
strs
-stripChars
-
-
stripAccents
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"
- Parameters:
str
-- Returns:
- input text with diacritics removed
- Since:
- 3.0
-
stripAccents
- Parameters:
strs
-
-
chomp
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") = ""
- Parameters:
str
- the String to chomp a newline from, may be null- Returns:
- String without newline,
null
if null String input
-
chomp
- Parameters:
strs
-
-
chop
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") = ""
- Parameters:
str
- the String to chop last character from, may be null- Returns:
- String without last character,
null
if null String input
-
chop
- Parameters:
strs
-
-
truncate
Truncates a String. This will turn "Now is the time for all good men" into "Now is the time for".
Specifically:
- If
str
is less thanmaxWidth
characters long, return it. - Else truncate it to
substring(str, 0, maxWidth)
. - If
maxWidth
is less than0
, throw anIllegalArgumentException
. - In no case will it return a String of length greater than
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
- Parameters:
str
- the String to truncate, may be nullmaxWidth
- maximum length of result String, must be positive- Returns:
- truncated String,
null
if null String input - Throws:
IllegalArgumentException
- IfmaxWidth
is less than0
- Since:
- 3.5
- If
-
truncate
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:
- If
str
is less thanmaxWidth
characters long, return it. - Else truncate it to
substring(str, offset, maxWidth)
. - If
maxWidth
is less than0
, throw anIllegalArgumentException
. - If
offset
is less than0
, throw anIllegalArgumentException
. - In no case will it return a String of length greater than
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
- Parameters:
str
- the String to truncate, may be nulloffset
- left edge of source StringmaxWidth
- maximum length of result String, must be positive- Returns:
- truncated String,
null
if null String input - Throws:
IllegalArgumentException
- Ifoffset
ormaxWidth
is less than0
- Since:
- 3.5
- If
-
deleteWhitespace
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"
- Parameters:
str
- the String to delete whitespace from, may be null- Returns:
-
deleteWhitespace
- Parameters:
strs
-
-
appendIfMissing
Append if missing.- Parameters:
str
-suffix
-- Returns:
-
appendIfMissingIgnoreCase
- Parameters:
str
-suffix
-- Returns:
-
prependIfMissing
Prepend if missing.- Parameters:
str
-prefix
-- Returns:
-
prependIfMissingIgnoreCase
- Parameters:
str
-prefix
-- Returns:
-
wrapIfMissing
Wrap if missing.- Parameters:
str
-prefixSuffix
-- Returns:
-
wrapIfMissing
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"
- Parameters:
str
-prefix
-suffix
-- Returns:
-
wrap
- Parameters:
str
-prefixSuffix
-- Returns:
-
wrap
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"
- Parameters:
str
-prefix
-suffix
-- Returns:
-
unwrap
- Parameters:
str
-prefixSuffix
-- Returns:
-
unwrap
Unwraps the specified string
str
if and only if it's wrapped by the specifiedprefix
andsuffix
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") -> ""
- Parameters:
str
-prefix
-suffix
-- Returns:
-
isLowerCase
public static boolean isLowerCase(char ch) Checks if is lower case.- Parameters:
ch
-- Returns:
- true, if is lower case
-
isAsciiLowerCase
public static boolean isAsciiLowerCase(char ch) Checks if is ascii lower case.- Parameters:
ch
-- Returns:
- true, if is ascii lower case
-
isUpperCase
public static boolean isUpperCase(char ch) Checks if is upper case.- Parameters:
ch
-- Returns:
- true, if is upper case
-
isAsciiUpperCase
public static boolean isAsciiUpperCase(char ch) Checks if is ascii upper case.- Parameters:
ch
-- Returns:
- true, if is ascii upper case
-
isAllLowerCase
Checks if is all lower case.- Parameters:
cs
-- Returns:
- true, if is all lower case
-
isAllUpperCase
Checks if is all upper case.- Parameters:
cs
-- Returns:
- true, if is all upper case
-
isMixedCase
Copied from Apache Commons Lang: StringUtils#isMixedCase.- Parameters:
cs
-- Returns:
- true, if is mixed case
-
isDigit
public static boolean isDigit(char ch) Checks if is digit.- Parameters:
ch
-- Returns:
- true, if is digit
- See Also:
-
isLetter
public static boolean isLetter(char ch) Checks if is letter.- Parameters:
ch
-- Returns:
- true, if is letter
- See Also:
-
isLetterOrDigit
public static boolean isLetterOrDigit(char ch) Checks if is letter or digit.- Parameters:
ch
-- Returns:
- true, if is letter or digit
- See Also:
-
isAscii
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
- Parameters:
ch
- the character to check- Returns:
- true if less than 128
-
isAsciiPrintable
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 32 and 126 inclusive
-
isAsciiControl
public 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
- Parameters:
ch
- the character to check- Returns:
- true if less than 32 or equals 127
-
isAsciiAlpha
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 65 and 90 or 97 and 122 inclusive
-
isAsciiAlphaUpper
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 65 and 90 inclusive
-
isAsciiAlphaLower
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 97 and 122 inclusive
-
isAsciiNumeric
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 48 and 57 inclusive
-
isAsciiAlphanumeric
public 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
- Parameters:
ch
- the character to check- Returns:
- true if between 48 and 57 or 65 and 90 or 97 and 122 inclusive
-
isAsciiPrintable
Checks if is ascii printable.- Parameters:
cs
-- Returns:
- true, if is ascii printable
-
isAsciiAlpha
Checks if is ascii alpha.- Parameters:
cs
-- Returns:
- true, if is ascii alpha
-
isAsciiAlphaSpace
Checks if is ascii alpha space.- Parameters:
cs
-- Returns:
- true, if is ascii alpha space
-
isAsciiAlphanumeric
Checks if is ascii alphanumeric.- Parameters:
cs
-- Returns:
- true, if is ascii alphanumeric
-
isAsciiAlphanumericSpace
Checks if is ascii alphanumeric space.- Parameters:
cs
-- Returns:
- true, if is ascii alphanumeric space
-
isAsciiNumeric
Checks if is ascii numeric.- Parameters:
cs
-- Returns:
- true, if is ascii numeric
-
isAlpha
Checks if the CharSequence contains only Unicode letters.
null
or empty CharSequence (length()=0) will returnfalse
.N.isAlpha(null) = false N.isAlpha("") = false N.isAlpha(" ") = false N.isAlpha("abc") = true N.isAlpha("ab2c") = false N.isAlpha("ab-c") = false
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains letters, and is non-null- Since:
- 3.0 Changed signature from isAlpha(String) to isAlpha(CharSequence), 3.0 Changed "" to return false and not true
-
isAlphaSpace
Checks if the CharSequence contains only Unicode letters and space (' ').
null
or empty CharSequence (length()=0) will returnfalse
.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
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains letters and space, and is non-null- Since:
- 3.0 Changed signature from isAlphaSpace(String) to isAlphaSpace(CharSequence)
-
isAlphanumeric
Checks if the CharSequence contains only Unicode letters or digits.
null
or empty CharSequence (length()=0) will returnfalse
.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
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains letters or digits, and is non-null- Since:
- 3.0 Changed signature from isAlphanumeric(String) to isAlphanumeric(CharSequence), 3.0 Changed "" to return false and not true
-
isAlphanumericSpace
Checks if the CharSequence contains only Unicode letters, digits or space (
' '
).null
or empty CharSequence (length()=0) will returnfalse
.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
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains letters, digits or space, and is non-null- Since:
- 3.0 Changed signature from isAlphanumericSpace(String) to isAlphanumericSpace(CharSequence)
-
isNumeric
Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false.
null
will returnfalse
. An empty CharSequence (length()=0) will returnfalse
.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
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains digits, and is non-null- Since:
- 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence), 3.0 Changed "" to return false and not true
-
isNumericSpace
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 returnfalse
.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
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains digits or space, and is non-null- Since:
- 3.0 Changed signature from isNumericSpace(String) to isNumericSpace(CharSequence)
-
isWhitespace
Checks if the CharSequence contains only whitespace.
null
or empty CharSequence (length()=0) will returnfalse
.N.isWhitespace(null) = false N.isWhitespace("") = false N.isWhitespace(" ") = true N.isWhitespace("abc") = false N.isWhitespace("ab2c") = false N.isWhitespace("ab-c") = false
- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if only contains whitespace, and is non-null- Since:
- 2.0, 3.0 Changed signature from isWhitespace(String) to isWhitespace(CharSequence)
-
isNumber
Deprecated.useNumbers.isNumber(String)
insteadNote: It's copied from NumberUtils in Apache Commons Lang under Apache License 2.0Checks whether the String a valid Java number.
true
is returned if there is a number which can be initialized bycreateNumber
with specified String.Null
and empty String will returnfalse
.- Parameters:
str
- theString
to check- Returns:
true
if the string is a correctly formatted number- Since:
- 3.3 the code supports hex
0Xhhh
and octal0ddd
validation - See Also:
-
isAsciiDigtalNumber
true
is returned if the specifiedstr
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" => true- Parameters:
str
-- Returns:
- true, if is ascii digtal number
-
isAsciiDigtalInteger
true
is returned if the specifiedstr
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" => false- Parameters:
str
-- Returns:
- true, if is ascii digtal integer
-
indexOf
- Parameters:
str
-targetChar
-- Returns:
-
indexOf
- Parameters:
str
-fromIndex
-targetChar
-- Returns:
-
indexOf
- Parameters:
str
-substr
-- Returns:
-
indexOf
- Parameters:
str
-fromIndex
-substr
-- Returns:
-
indexOfAny
- Parameters:
str
-chs
-- Returns:
-
indexOfAny
- Parameters:
str
-fromIndex
-chs
-- Returns:
-
indexOfAny
- Parameters:
str
-substrs
-- Returns:
- See Also:
-
indexOfAny
- Parameters:
str
-fromIndex
-substrs
-- Returns:
- See Also:
-
indexOfAnyBut
Index of any but.- Parameters:
str
-chs
-- Returns:
-
indexOfAnyBut
- Parameters:
str
-fromIndex
-chs
-- Returns:
-
indexOf
- Parameters:
str
-substr
-delimiter
-- Returns:
-
indexOf
- Parameters:
str
-fromIndex
- the index from which to start the search.substr
-delimiter
-- Returns:
-
indexOfIgnoreCase
Index of ignore case.- Parameters:
str
-substr
-- Returns:
-
indexOfIgnoreCase
Index of ignore case.- Parameters:
str
-fromIndex
-substr
-- Returns:
-
lastIndexOf
Last index of.- Parameters:
str
-targetChar
-- Returns:
-
lastIndexOf
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. For values ofch
in the range from 0 to 0xFFFF (inclusive), the index returned is the largest value k such that:(this.charAt(k) == ch) && (k <= fromIndex)
ch
, it is the largest value k such that:(this.codePointAt(k) == ch) && (k <= fromIndex)
fromIndex
, then-1
is returned.All indices are specified in
char
values (Unicode code units).- Parameters:
str
-fromIndex
- the index to start the search from. There is no restriction on the value offromIndex
. 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).- Returns:
- character sequence represented by this object that is less than
or equal to
fromIndex
, or-1
if the character does not occur before that point.
-
lastIndexOf
Last index of.- Parameters:
str
-substr
-- Returns:
-
lastIndexOf
Returns the index withinstr
of the last occurrence of the specifiedsubstr
, searching backward starting at the specified index.The returned index is the largest value k for which:
k <= fromIndex && str.startsWith(substr, k)
-1
is returned.- Parameters:
str
-fromIndex
-substr
-- Returns:
-
lastIndexOf
Last index of.- Parameters:
str
-substr
-delimiter
-- Returns:
-
lastIndexOf
Last index of.- Parameters:
str
-fromIndex
- the start index to traverse backwards fromsubstr
-delimiter
-- Returns:
-
lastIndexOfIgnoreCase
Last index of ignore case.- Parameters:
str
-substr
-- Returns:
-
lastIndexOfIgnoreCase
Last index of ignore case.- Parameters:
str
-fromIndex
-substr
-- Returns:
-
lastIndexOfAny
Last index of any.- Parameters:
str
-chs
-- Returns:
-
lastIndexOfAny
Last index of any.- Parameters:
str
-substrs
-- Returns:
- See Also:
-
smallestIndexOfAll
Find the first index of any of a set of potential substrings.
- Parameters:
str
-substrs
-- Returns:
- See Also:
-
smallestIndexOfAll
Find the first index of any of a set of potential substrings from
fromIndex
.- Parameters:
str
-fromIndex
-substrs
-- Returns:
- See Also:
-
largestIndexOfAll
Last index of any.- Parameters:
str
-substrs
-- Returns:
- See Also:
-
ordinalIndexOf
Finds the n-th index within a String, handling
null
.- Parameters:
str
-substr
-ordinal
- the n-thsearchStr
to find- Returns:
N.INDEX_NOT_FOUND
) if no match ornull
or empty string input
-
lastOrdinalIndexOf
Finds the n-th last index within a String, handling
null
.- Parameters:
str
-substr
-ordinal
- the n-th lastsearchStr
to find- Returns:
N.INDEX_NOT_FOUND
) if no match ornull
or empty string input
-
occurrencesOf
- Parameters:
str
-ch
-- Returns:
- See Also:
-
occurrencesOf
- Parameters:
str
-substr
-- Returns:
- See Also:
-
contains
- Parameters:
str
-targetChar
-- Returns:
-
contains
- Parameters:
str
-substr
-- Returns:
-
contains
- Parameters:
str
-substr
-delimiter
-- Returns:
-
containsIgnoreCase
Contains ignore case.- Parameters:
str
-substr
-- Returns:
-
containsAny
- Parameters:
str
-chs
-- Returns:
-
containsAny
- Parameters:
str
-searchStrs
-- Returns:
-
containsAnyIgnoreCase
- Parameters:
str
-searchStrs
-- Returns:
-
containsOnly
- Parameters:
str
-chs
-- Returns:
-
containsNone
- Parameters:
str
-chs
-- Returns:
-
containsWhitespace
- Parameters:
str
-- Returns:
-
startsWith
- Parameters:
str
-prefix
-- Returns:
-
startsWithIgnoreCase
Starts with ignore case.- Parameters:
str
-prefix
-- Returns:
-
startsWithAny
Starts with any.- Parameters:
str
-substrs
-- Returns:
-
startsWithAnyIgnoreCase
Starts with any.- Parameters:
str
-substrs
-- Returns:
-
endsWith
- Parameters:
str
-suffix
-- Returns:
-
endsWithIgnoreCase
Ends with ignore case.- Parameters:
str
-suffix
-- Returns:
-
endsWithAny
Ends with any.- Parameters:
str
-substrs
-- Returns:
-
endsWithAnyIgnoreCase
Ends with ignore case.- Parameters:
str
-substrs
-- Returns:
-
equals
- Parameters:
a
-b
-- Returns:
-
equalsIgnoreCase
Equals ignore case.- Parameters:
a
-b
-- Returns:
-
equalsAny
Equals with any.- Parameters:
str
-searchStrings
-- Returns:
-
equalsAnyIgnoreCase
Equals with any.- Parameters:
str
-searchStrs
-- Returns:
-
indexOfDifference
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
- Parameters:
a
- the first String, may be nullb
- the second String, may be null- Returns:
-
indexOfDifference
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
- Parameters:
strs
- array of Strings, entries may be null- Returns:
- equal or null/empty
-
commonPrefix
Note: copy rights: Google Guava. Returns the longest stringprefix
such thata.toString().startsWith(prefix) && b.toString().startsWith(prefix)
, taking care not to split surrogate pairs. Ifa
andb
have no common prefix, returns the empty string.- Parameters:
a
-b
-- Returns:
-
commonPrefix
- Parameters:
strs
-- Returns:
-
commonSuffix
Note: copy rights: Google Guava. Returns the longest stringsuffix
such thata.toString().endsWith(suffix) && b.toString().endsWith(suffix)
, taking care not to split surrogate pairs. Ifa
andb
have no common suffix, returns the empty string.- Parameters:
a
-b
-- Returns:
-
commonSuffix
- Parameters:
strs
-- Returns:
-
longestCommonSubstring
- Parameters:
a
-b
-- Returns:
- an empty String
""
isa
orb
is empty ornull
.
-
countMatches
- Parameters:
str
-ch
-- Returns:
-
countMatches
- Parameters:
str
-substr
-- Returns:
-
substring
Returnsnull
ifinclusiveBeginIndex < 0
, otherwise thesubstring
with String value:str.substring(inclusiveBeginIndex)
is returned.- Parameters:
str
-inclusiveBeginIndex
-- Returns:
- See Also:
-
substring
Returnsnull
ifN.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0
, otherwise thesubstring
with String value:str.substring(str.indexOf(delimiterOfInclusiveBeginIndex))
is returned.- Parameters:
str
-delimiterOfInclusiveBeginIndex
-inclusiveBeginIndex <- str.indexOf(delimiterOfInclusiveBeginIndex)
- Returns:
- See Also:
-
substring
Returnsnull
ifN.isNullOrEmpty(str) || str.indexOf(delimiterOfInclusiveBeginIndex) < 0
, otherwise thesubstring
with String value:str.substring(str.indexOf(delimiterOfInclusiveBeginIndex))
is returned.- Parameters:
str
-delimiterOfInclusiveBeginIndex
-inclusiveBeginIndex <- str.indexOf(delimiterOfInclusiveBeginIndex)
- Returns:
- See Also:
-
substring
Returnsnull
ifinclusiveBeginIndex < 0 ||exclusiveEndIndex <= 0 || inclusiveBeginIndex > exclusiveEndIndex
, otherwise thesubstring
with String value:str.substring(exclusiveBeginIndex, exclusiveEndIndex)
is returned.- Parameters:
str
-inclusiveBeginIndex
-exclusiveEndIndex
-- Returns:
-
substring
public static String substring(String str, int inclusiveBeginIndex, char delimiterOfExclusiveEndIndex) Returnsnull
ifstr == null || str.length() == 0 || inclusiveBeginIndex < 0
.- Parameters:
str
-inclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) if inclusiveBeginIndex >= 0
, orstr.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) < 0
- Returns:
- See Also:
-
substring
public static String substring(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex) Returnsnull
if(str == null || inclusiveBeginIndex < 0 || delimiterOfExclusiveEndIndex == null)
, orstr.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) < 0
.- Parameters:
str
-inclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, inclusiveBeginIndex + 1) if inclusiveBeginIndex >= 0
- Returns:
- See Also:
-
substring
public static String substring(String str, int inclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex) Returnsnull
if(str == null || inclusiveBeginIndex < 0)
, orfuncOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) < 0
.- Parameters:
str
-inclusiveBeginIndex
-funcOfExclusiveEndIndex
-exclusiveEndIndex <- funcOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) if inclusiveBeginIndex >= 0
- Returns:
- See Also:
-
substring
public static String substring(String str, char delimiterOfInclusiveBeginIndex, int exclusiveEndIndex) Returnsnull
if(str == null || str.length() == 0 || exclusiveEndIndex <= 0)
, orstr.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) < 0
.- Parameters:
str
-delimiterOfInclusiveBeginIndex
-inclusiveBeginIndex <- str.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substring
public static String substring(String str, String delimiterOfInclusiveBeginIndex, int exclusiveEndIndex) Returnsnull
if(str == null || delimiterOfInclusiveBeginIndex == null ||exclusiveEndIndex <= 0)
, orstr.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) < 0
.- Parameters:
str
-delimiterOfInclusiveBeginIndex
-inclusiveBeginIndex <- str.lastIndexOf(delimiterOfInclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substring
public static String substring(String str, IntUnaryOperator funcOfInclusiveBeginIndex, int exclusiveEndIndex) Returnsnull
if(str == null ||exclusiveEndIndex <= 0)
, orfuncOfInclusiveBeginIndex.applyAsInt(exclusiveEndIndex) < 0
.- Parameters:
str
-funcOfInclusiveBeginIndex
-inclusiveBeginIndex <- funcOfInclusiveBeginIndex.applyAsInt(exclusiveEndIndex)) if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substringAfter
Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-- Returns:
-
substringAfter
Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-- Returns:
-
substringAfter
public static String substringAfter(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) Returns the substring after firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-exclusiveEndIndex
-- Returns:
-
substringAfterLast
Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-- Returns:
-
substringAfterLast
Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-- Returns:
-
substringAfterLast
public static String substringAfterLast(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) Returns the substring after lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveBeginIndex
-exclusiveEndIndex
-- Returns:
-
substringAfterAny
Returns the substring before any ofdelimitersOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimitersOfExclusiveBeginIndex
-- Returns:
- See Also:
-
substringAfterAny
Returns the substring before any ofdelimitersOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimitersOfExclusiveBeginIndex
-- Returns:
- See Also:
-
substringBefore
Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBefore
Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBefore
public static String substringBefore(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex) Returns the substring before firstdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-inclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBeforeLast
Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBeforeLast
Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBeforeLast
public static String substringBeforeLast(String str, int inclusiveBeginIndex, String delimiterOfExclusiveEndIndex) Returns the substring before lastdelimiterOfExclusiveBeginIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-inclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-- Returns:
-
substringBeforeAny
Returns the substring before any ofdelimitersOfExclusiveEndIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimitersOfExclusiveEndIndex
-- Returns:
- See Also:
-
substringBeforeAny
Returns the substring before any ofdelimitersOfExclusiveEndIndex
if it exists, otherwise returnnull
String.- Parameters:
str
-delimitersOfExclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
Returnsnull
ifexclusiveBeginIndex < 0 ||exclusiveEndIndex <= 0 || exclusiveBeginIndex >= exclusiveEndIndex
, otherwise thesubstring
with String value:str.substring(exclusiveBeginIndex + 1, exclusiveEndIndex)
is returned.- Parameters:
str
-exclusiveBeginIndex
-exclusiveEndIndex
-- Returns:
-
substringBetween
public static String substringBetween(String str, int exclusiveBeginIndex, char delimiterOfExclusiveEndIndex) - Parameters:
str
-exclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, beginIndex + 1) if exclusiveBeginIndex >= 0
- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, int exclusiveBeginIndex, String delimiterOfExclusiveEndIndex) - Parameters:
str
-exclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-exclusiveEndIndex <- str.indexOf(delimiterOfExclusiveEndIndex, beginIndex + 1) if exclusiveBeginIndex >= 0
- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, int exclusiveBeginIndex, IntUnaryOperator funcOfExclusiveEndIndex) - Parameters:
str
-exclusiveBeginIndex
-funcOfExclusiveEndIndex
-exclusiveEndIndex <- funcOfExclusiveEndIndex.applyAsInt(inclusiveBeginIndex) if inclusiveBeginIndex >= 0
- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, char delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) - Parameters:
str
-delimiterOfExclusiveBeginIndex
-exclusiveBeginIndex <- str.lastIndexOf(delimiterOfExclusiveBeginIndex, exclusiveEndIndex - 1) if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, String delimiterOfExclusiveBeginIndex, int exclusiveEndIndex) - Parameters:
str
-delimiterOfExclusiveBeginIndex
-exclusiveBeginIndex <- str.lastIndexOf(delimiterOfExclusiveBeginIndex, exclusiveEndIndex - 1) + delimiterOfExclusiveBeginIndex.length() - 1 if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, IntUnaryOperator funcOfExclusiveBeginIndex, int exclusiveEndIndex) - Parameters:
str
-funcOfExclusiveBeginIndex
-exclusiveBeginIndex <- funcOfExclusiveBeginIndex.applyAsInt(exclusiveEndIndex)) if exclusiveEndIndex > 0
exclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, char delimiterOfExclusiveBeginIndex, char delimiterOfExclusiveEndIndex) - Parameters:
str
-delimiterOfExclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
- Parameters:
str
-tag
-- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, String delimiterOfExclusiveBeginIndex, String delimiterOfExclusiveEndIndex) - Parameters:
str
-delimiterOfExclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-- Returns:
- See Also:
-
substringBetween
public static String substringBetween(String str, int fromIndex, String delimiterOfExclusiveBeginIndex, String delimiterOfExclusiveEndIndex) - Parameters:
str
-fromIndex
- start index fordelimiterOfExclusive
.str.indexOf(delimiterOfExclusiveBeginIndex, fromIndex)
delimiterOfExclusiveBeginIndex
-delimiterOfExclusiveEndIndex
-- Returns:
- See Also:
-
findAllIndicesBetween
findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.- Parameters:
str
-prefix
-postfix
-- Returns:
-
findAllIndicesBetween
public static List<IntPair> findAllIndicesBetween(String str, int fromIndex, int toIndex, char prefix, char postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.- Parameters:
str
-fromIndex
-toIndex
-prefix
-postfix
-- Returns:
-
findAllIndicesBetween
findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.- Parameters:
str
-prefix
-postfix
-- Returns:
-
findAllIndicesBetween
public static List<IntPair> findAllIndicesBetween(String str, int fromIndex, int toIndex, String prefix, String postfix) findAllIndicesBetween("3[a2[c]]2[a]", '[', ']') = [[2, 7], [10, 11]]
.- Parameters:
str
-fromIndex
-toIndex
-prefix
-postfix
-- Returns:
-
findAllSubstringsBetween
findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.- Parameters:
str
-prefix
-postfix
-- Returns:
-
findAllSubstringsBetween
public static List<String> findAllSubstringsBetween(String str, int fromIndex, int toIndex, char prefix, char postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.- Parameters:
str
-fromIndex
-toIndex
-prefix
-postfix
-- Returns:
-
findAllSubstringsBetween
findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.- Parameters:
str
-prefix
-postfix
-- Returns:
-
findAllSubstringsBetween
public static List<String> findAllSubstringsBetween(String str, int fromIndex, int toIndex, String prefix, String postfix) findAllSubstringsBetween("3[a2[c]]2[a]", '[', ']') = [a2[c], a]
.- Parameters:
str
-fromIndex
-toIndex
-prefix
-postfix
-- Returns:
-
firstChar
- Parameters:
str
-- Returns:
-
lastChar
- Parameters:
str
-- Returns:
-
firstChars
Returns at most firstn
chars of the specifiedString
if its length is bigger thann
, or an empty String""
ifstr
is empty or null, or itself it's length equal to or less thann
.- Parameters:
str
-n
-- Returns:
-
lastChars
Returns at most lastn
chars of the specifiedString
if its length is bigger thann
, or an empty String""
ifstr
is empty or null, or itself it's length equal to or less thann
.- Parameters:
str
-n
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(boolean[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(char[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(byte[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(short[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(int[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(long[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(float[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(double[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-- Returns:
-
join
- Parameters:
a
-delimiter
-prefix
-suffix
-- Returns:
-
join
- Parameters:
a
-delimiter
-prefix
-suffix
-trim
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-trim
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
- Parameters:
a
-fromIndex
-toIndex
-delimiter
-trim
-- Returns:
-
join
public static String join(Object[] a, int fromIndex, int toIndex, String delimiter, String prefix, String suffix, boolean trim) - Parameters:
a
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-trim
-- Returns:
-
join
- Parameters:
c
-- Returns:
-
join
- Parameters:
c
-delimiter
-- Returns:
-
join
- Parameters:
c
-delimiter
-- Returns:
-
join
- Parameters:
c
-delimiter
-prefix
-suffix
-- Returns:
-
join
public static String join(Iterable<?> c, String delimiter, String prefix, String suffix, boolean trim) - Parameters:
c
-delimiter
-prefix
-suffix
-trim
-- Returns:
-
join
- Parameters:
c
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(Collection<?> c, int fromIndex, int toIndex, char delimiter, boolean trim) - Parameters:
c
-fromIndex
-toIndex
-delimiter
-trim
-- Returns:
-
join
- Parameters:
c
-fromIndex
-toIndex
-delimiter
-- Returns:
-
join
public static String join(Collection<?> c, int fromIndex, int toIndex, String delimiter, boolean trim) - Parameters:
c
-fromIndex
-toIndex
-delimiter
-trim
-- Returns:
-
join
public static String join(Collection<?> c, int fromIndex, int toIndex, String delimiter, String prefix, String suffix, boolean trim) - Parameters:
c
-fromIndex
-toIndex
-delimiter
-prefix
-suffix
-trim
-- Returns:
-
join
- Parameters:
iter
-- Returns:
-
join
- Parameters:
iter
-delimiter
-- Returns:
-
join
- Parameters:
iter
-delimiter
-- Returns:
-
join
- Parameters:
iter
-delimiter
-prefix
-suffix
-- Returns:
-
join
public static String join(Iterator<?> iter, String delimiter, String prefix, String suffix, boolean trim) - Parameters:
iter
-delimiter
-prefix
-suffix
-trim
-- Returns:
-
joinEntries
- Parameters:
m
-- Returns:
-
joinEntries
- Parameters:
m
-entryDelimiter
-- Returns:
-
joinEntries
- Parameters:
m
-entryDelimiter
-- Returns:
-
joinEntries
- Parameters:
m
-entryDelimiter
-keyValueDelimiter
-- Returns:
-
joinEntries
- Parameters:
m
-entryDelimiter
-keyValueDelimiter
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix) - Parameters:
m
-entryDelimiter
-keyValueDelimiter
-prefix
-suffix
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim) - Parameters:
m
-entryDelimiter
-keyValueDelimiter
-prefix
-suffix
-trim
-- Returns:
-
joinEntries
public static <K,V, String joinEntriesE extends Exception, E2 extends Exception> (Map<K, V> m, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim, Throwables.Function<? super K, throws E, E2?, E> keyMapper, Throwables.Function<? super V, ?, E2> valueMapper) - Type Parameters:
K
-V
-E
-E2
-- Parameters:
m
-entryDelimiter
-keyValueDelimiter
-prefix
-suffix
-trim
-keyMapper
-valueMapper
-- Returns:
- Throws:
E
E2
-
joinEntries
- Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, char entryDelimiter, boolean trim) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-trim
-- Returns:
-
joinEntries
- Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, String entryDelimiter, boolean trim) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-trim
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, char entryDelimiter, char keyValueDelimiter) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-keyValueDelimiter
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, char entryDelimiter, char keyValueDelimiter, boolean trim) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-keyValueDelimiter
-trim
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, String entryDelimiter, String keyValueDelimiter) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-keyValueDelimiter
-- Returns:
-
joinEntries
public static String joinEntries(Map<?, ?> m, int fromIndex, int toIndex, String entryDelimiter, String keyValueDelimiter, String prefix, String suffix, boolean trim) - Parameters:
m
-fromIndex
-toIndex
-entryDelimiter
-keyValueDelimiter
-prefix
-suffix
-trim
-- Returns:
-
concat
Returnsa + b
.- Parameters:
a
-b
-- Returns:
-
concat
- Parameters:
a
-b
-c
-- Returns:
-
concat
- Parameters:
a
-b
-c
-d
-- Returns:
-
concat
- Parameters:
a
-b
-c
-d
-e
-- Returns:
-
concat
- Parameters:
a
-b
-c
-d
-e
-f
-- Returns:
-
concat
- Parameters:
a
-b
-c
-d
-e
-f
-g
-- Returns:
-
concat
public static String concat(String a, String b, String c, String d, String e, String f, String g, String h) - Parameters:
a
-b
-c
-d
-e
-f
-g
-h
-- Returns:
-
concat
public static String concat(String a, String b, String c, String d, String e, String f, String g, String h, String i) - Parameters:
a
-b
-c
-d
-e
-f
-g
-h
-i
-- Returns:
-
concat
- Parameters:
a
-- Returns:
-
concat
ReturnsN.toString(a) + N.toString(b)
.- Parameters:
a
-b
-- Returns:
-
concat
- Parameters:
a
-b
-c
-- Returns:
- See Also:
-
concat
- Parameters:
a
-b
-c
-d
-- Returns:
- See Also:
-
concat
- Parameters:
a
-b
-c
-d
-e
-- Returns:
- See Also:
-
concat
- Parameters:
a
-b
-c
-d
-e
-f
-- Returns:
- See Also:
-
concat
ReturnsN.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g)
.- Parameters:
a
-b
-c
-d
-e
-f
-g
-- Returns:
- See Also:
-
concat
public static String concat(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h) ReturnsN.toString(a) + N.toString(b) + N.toString(c) + N.toString(d) + N.toString(e) + N.toString(f) + N.toString(g) + N.toString(h)
.- Parameters:
a
-b
-c
-d
-e
-f
-g
-h
-- Returns:
- See Also:
-
concat
public static String concat(Object a, Object b, Object c, Object d, Object e, Object f, Object g, Object h, Object i) ReturnsN.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)
.- Parameters:
a
-b
-c
-d
-e
-f
-g
-h
-i
-- Returns:
- See Also:
-
lenientFormat
Copied from Google Guava
Returns the giventemplate
string with each occurrence of"%s"
replaced by the corresponding argument value fromargs
; 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 throwingIllegalFormatException
.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 thePreconditions
class use this formatter, for both of the reasons just discussed.Warning: Only the exact two-character placeholder sequence
"%s"
is recognized.- Parameters:
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. Anull
argument is converted to the four-character string"null"
; non-null values are converted to strings usingObject.toString()
.- Returns:
- Since:
- 25.1
-
reverse
- Parameters:
str
-- Returns:
-
reverseDelimited
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"
- Parameters:
str
- the String to reverse, may be nulldelimiter
- the delimiter character to use- Returns:
- Since:
- 2.0
-
reverseDelimited
- Parameters:
str
-delimiter
-- Returns:
-
sort
Returns a new sorted String if the specifiedstr
is not null or empty, otherwise the specifiedstr
is returned.- Parameters:
str
-- Returns:
-
rotate
Rotate (circular shift) a String of
shift
characters.- If
shift > 0
, right circular shift (ex : ABCDEF => FABCDE) - If
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"
- Parameters:
str
- the String to rotate, may be nullshift
- number of time to shift (positive : right shift, negative : left shift)- Returns:
- the rotated String,
or the original String if
shift == 0
, ornull
if null String input - Since:
- 3.5
- If
-
shuffle
- Parameters:
str
-- Returns:
-
shuffle
- Parameters:
str
-rnd
-- Returns:
-
overlay
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"
- Parameters:
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- Returns:
- overlayed String,
""
if null String input - Since:
- 2.0
-
copyThenTrim
- Parameters:
strs
-- Returns:
- See Also:
-
copyThenStrip
- Parameters:
strs
-- Returns:
- See Also:
-
Numbers.isNumber(String)
instead