public class Strings extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
append2Digits(Appendable a,
int i)
Append an
int to an Appendable as two decimal digits. |
static void |
append3Digits(Appendable a,
int i)
Append an
int to an Appendable as three decimal digits. |
static Appendable |
appendEnglish(Appendable a,
int n)
Append a number converted to words in English to an
Appendable. |
static void |
appendEscaped(Appendable a,
CharSequence s,
CharMapper mapper)
Append characters to an
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. |
static void |
appendEscaped(Appendable a,
CharSequence s,
int index,
int end,
CharMapper mapper)
Append characters to an
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. |
static void |
appendEscapedUTF16(Appendable a,
CharSequence s,
CharMapper mapper)
Append characters to an
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. |
static void |
appendEscapedUTF16(Appendable a,
CharSequence s,
int index,
int end,
CharMapper mapper)
Append characters to an
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. |
static void |
appendHex(Appendable a,
byte b)
Append a byte value as hexadecimal to an
Appendable. |
static void |
appendHex(Appendable a,
char ch)
Append a character value as hexadecimal to an
Appendable. |
static void |
appendHex(Appendable a,
int i)
Append an integer value as hexadecimal to an
Appendable. |
static void |
appendHex(Appendable a,
int i,
int digits)
Append an integer value as hexadecimal to an
Appendable, specifying the number of
output digits. |
static void |
appendHex(Appendable a,
long n)
Append a long value as hexadecimal to an
Appendable. |
static void |
appendHex(Appendable a,
long n,
int digits)
Append a long value as hexadecimal to an
Appendable, specifying the number of
output digits. |
static void |
appendInt(Appendable a,
int i)
Append an
int to an Appendable. |
static void |
appendLong(Appendable a,
long n)
Append a
long to an Appendable. |
static void |
appendPositiveInt(Appendable a,
int i)
Append a positive
int to an Appendable. |
static void |
appendPositiveLong(Appendable a,
long n)
Append a positive
long to an Appendable. |
static void |
appendUTF16(Appendable a,
int codePoint)
Append a Unicode code point to an
Appendable. |
static void |
appendUTF8(ByteArrayBuilder bab,
int codepoint)
Append a codepoint to a
ByteArrayBuilder as UTF-8. |
static StringBuilder |
build()
Convenience method to create a
StringBuilder. |
static StringBuilder |
build(CharSequence cs)
Convenience method to create a
StringBuilder. |
static String |
capitalise(String str)
Capitalise the first letter of a string.
|
static int |
convertDecDigit(char ch)
Convert a decimal digit to the integer value of the digit.
|
static int |
convertHexDigit(char ch)
Convert a hexadecimal digit to the integer value of the digit.
|
static int |
convertHexToInt(CharSequence text,
int start,
int end)
Convert a group of hexadecimal digits in a
CharSequence to an int. |
static long |
convertHexToLong(CharSequence text,
int start,
int end)
Convert a group of hexadecimal digits in a
CharSequence to a long. |
static int |
convertToInt(CharSequence text,
int start,
int end)
Convert a group of digits in a
CharSequence to an int. |
static long |
convertToLong(CharSequence text,
int start,
int end)
Convert a group of digits in a
CharSequence to a long. |
static CharSequence |
escape(CharSequence s,
CharMapper mapper)
Replace certain characters in a
CharSequence with their mapped equivalents, as
specified in the provided CharMapper instance. |
static String |
escape(String s,
CharMapper mapper)
Replace certain characters in a string with their mapped equivalents, as specified in the
provided
CharMapper instance. |
static CharSequence |
escapeUTF16(CharSequence s,
CharMapper mapper)
Replace certain characters in a
CharSequence with their mapped equivalents, as
specified in the provided CharMapper instance. |
static String |
escapeUTF16(String s,
CharMapper mapper)
Replace certain characters in a string with their mapped equivalents, as specified in the
provided
CharMapper instance. |
static String |
fromUTF8(byte[] bytes)
Convert a byte array from UTF-8 encoding to a UTF-16 string.
|
static String |
fromUTF8(byte[] bytes,
int start,
int end)
Convert a portion of a byte array from UTF-8 encoding to a UTF-16 string.
|
static String |
fromUTF8(ByteBuffer byteBuffer)
Convert a sequence of bytes in a
ByteBuffer from UTF-8 encoding to a UTF-16 string. |
static String |
fromUTF8(ByteBuffer[] byteBuffers)
Convert a sequence of bytes in an array of
ByteBuffers from UTF-8 encoding to a UTF-16 string. |
static String |
fromUTF8(Iterator<Byte> byteIterator)
Convert a sequence of bytes described by an
Iterator from UTF-8 encoding to a UTF-16 string. |
static <E> String |
join(E[] array)
Join the string representations of the members of an array.
|
static <E> String |
join(E[] array,
char separator)
Join the string representations of the members of an array, with the specified character
separator.
|
static <E> String |
join(E[] array,
String separator)
Join the string representations of the members of an array, with the specified string
separator.
|
static <E> String |
join(Enumeration<E> e)
Join the string representations of the members of an
Enumeration. |
static <E> String |
join(Enumeration<E> e,
char separator)
Join the string representations of the members of an
Enumeration, with the
specified character separator. |
static <E> String |
join(Enumeration<E> e,
String separator)
Join the string representations of the members of an
Enumeration, with the
specified string separator. |
static <E> String |
join(Iterable<E> collection)
Join the string representations of the members of a collection.
|
static <E> String |
join(Iterable<E> collection,
char separator)
Join the string representations of the members of a collection, with the specified
character separator.
|
static <E> String |
join(Iterable<E> collection,
String separator)
Join the string representations of the members of a collection, with the specified string
separator.
|
static <E> String |
join(Iterator<E> it)
Join the string representations of the members of an
Iterator. |
static <E> String |
join(Iterator<E> it,
char separator)
Join the string representations of the members of an
Iterator, with the specified
character separator. |
static <E> String |
join(Iterator<E> it,
String separator)
Join the string representations of the members of an
Iterator, with the specified
string separator. |
static boolean |
multiWildcardCompare(String pattern,
CharSequence target)
Perform multi-wildcard comparison.
|
static String |
plural(String noun,
int n)
Create a string consisting of a number, space, and the singular or plural form of a given
noun (using standard English plural forms, i.e. add the letter "s").
|
static String |
plural(String singularNoun,
String pluralNoun,
int n)
Create a string consisting of a number, space, and the singular or plural noun (for use
with irregular plurals).
|
static String[] |
split(String s)
Split a string into white space delimited tokens, where white space is determined by
Character.isWhitespace(char). |
static String[] |
split(String s,
char separator)
Split a string on a given separator.
|
static String[] |
split(String s,
char separator,
boolean skipEmpty,
IntPredicate spaceTest)
Split a string on a given separator character.
|
static String[] |
split(String s,
int start,
int end)
Split a portion of a string into white space delimited tokens, where white space is
determined by
Character.isWhitespace(char). |
static String[] |
split(String s,
int start,
int end,
char separator,
boolean skipEmpty,
IntPredicate spaceTest)
Split a portion of a string on a given separator character.
|
static String[] |
split(String s,
int start,
int end,
IntPredicate spaceTest)
Split a portion of a string into white space delimited tokens, where white space is
determined by a supplied
IntPredicate function. |
static String[] |
split(String s,
IntPredicate spaceTest)
Split a string into white space delimited tokens, where white space is determined by a
supplied
IntPredicate function. |
static String[] |
split(String s1,
String s2)
Split a string on a given string separator.
|
static CharSequence |
strip(CharSequence cs,
IntPredicate test)
Strip characters from a
CharSequence, where those characters match a supplied
IntPredicate function. |
static String |
strip(String s,
IntPredicate test)
Strip characters from a string, where those characters match a supplied
IntPredicate function. |
static String |
stripUTF16(String s,
IntPredicate test)
Strip code points from a UTF16 string, where those code points match a supplied
IntPredicate function. |
static String |
toEnglish(int n)
Convert a number to words in English.
|
static String |
toHex(byte b)
Convert a byte to hexadecimal.
|
static String |
toHex(byte[] bytes)
Convert a byte array to hexadecimal.
|
static String |
toHex(byte[] bytes,
char separator)
Convert a byte array to hexadecimal, with a separator between bytes for easier reading.
|
static String |
toHex(char ch)
Convert a character to hexadecimal.
|
static String |
toHex(CharSequence s)
Convert a
CharSequence to hexadecimal. |
static String |
toHex(CharSequence s,
char separator)
Convert a
CharSequence to hexadecimal, with a separator between bytes for easier
reading. |
static String |
toHex(int i)
Convert an integer to hexadecimal.
|
static String |
toHex(long n)
Convert a long to hexadecimal.
|
static String |
toIdentifier(int i)
Convert an integer to a spreadsheet-style column identifier ("A", "B", ...
|
static String |
toUTF16(int codePoint)
Convert a Unicode code point to a one- or two-character string.
|
static String |
toUTF16(int[] codePoints)
Convert an array of Unicode code points to a string.
|
static byte[] |
toUTF8(String str)
Convert a string to UTF-8 encoding.
|
static byte[] |
toUTF8(String str,
int start,
int end)
Convert a portion of a string to UTF-8 encoding.
|
static CharSequence |
trim(CharSequence cs)
Trim leading and trailing whitespace from a
CharSequence, where white space is determined by
Character.isWhitespace(char). |
static CharSequence |
trim(CharSequence cs,
IntPredicate test)
Trim leading and trailing characters from a
CharSequence, where those characters
match a supplied IntPredicate function. |
static String |
trim(String s)
Trim leading and trailing whitespace from a string, where white space is determined by
Character.isWhitespace(char). |
static String |
trim(String s,
IntPredicate test)
Trim leading and trailing characters from a string, where those characters match a
supplied
IntPredicate function. |
static CharSequence |
trimLeading(CharSequence cs)
Trim leading whitespace from a
CharSequence, where white space is determined by
Character.isWhitespace(char). |
static CharSequence |
trimLeading(CharSequence cs,
IntPredicate test)
Trim leading characters from a
CharSequence, where those characters match a supplied IntPredicate
function. |
static String |
trimLeading(String s)
Trim leading whitespace from a string, where white space is determined by
Character.isWhitespace(char). |
static String |
trimLeading(String s,
IntPredicate test)
Trim leading characters from a string, where those characters match a supplied
IntPredicate function. |
static CharSequence |
trimTrailing(CharSequence cs)
Trim trailing whitespace from a
CharSequence, where white space is determined by
Character.isWhitespace(char). |
static CharSequence |
trimTrailing(CharSequence cs,
IntPredicate test)
Trim leading characters from a
CharSequence, where those characters match a supplied IntPredicate
function. |
static String |
trimTrailing(String s)
Trim trailing whitespace from a string, where white space is determined by
Character.isWhitespace(char). |
static String |
trimTrailing(String s,
IntPredicate test)
Trim trailing characters from a string, where those characters match a supplied
IntPredicate function. |
static String |
trimUTF16(String s,
IntPredicate test)
Trim leading and trailing code points from a UTF16 string, where those code points match
a supplied
IntPredicate function. |
static CharSequence |
unescape(CharSequence s,
CharUnmapper unmapper)
Scan a
CharSequence for escape sequences and replace them by the original
characters. |
static String |
unescape(String s,
CharUnmapper unmapper)
Scan a string for escape sequences and replace them by the original characters.
|
static boolean |
wildcardCompare(String pattern,
CharSequence target)
Perform wildcard comparison.
|
static boolean |
wildcardCompare(String pattern,
int patIndex,
int patEnd,
CharSequence target)
Perform wildcard comparison.
|
public static String toEnglish(int n)
n - the numberpublic static Appendable appendEnglish(Appendable a, int n) throws IOException
Appendable.a - the Appendablen - the numberAppendable (for chaining)IOException - if thrown by the Appendablepublic static String capitalise(String str)
str - the input stringpublic static String plural(String noun, int n)
Strings.plural("file", 23);
will return:
"23 files"
noun - the nounn - the numberpublic static String plural(String singularNoun, String pluralNoun, int n)
Strings.plural("axis", "axes", 2);
will return:
"2 axes"
singularNoun - the singular nounpluralNoun - the plural nounn - the numberpublic static String[] split(String s)
Character.isWhitespace(char).s - the string to be splitNullPointerException - if the input string is nullpublic static String[] split(String s, int start, int end)
Character.isWhitespace(char).s - the string to be splitstart - the start index of the portion to be examinedend - the end index (exclusive) of the portion to be examinedNullPointerException - if the input string is nullIndexOutOfBoundsException - if start or end is invalidpublic static String[] split(String s, IntPredicate spaceTest)
IntPredicate function. In lambda notation, this may be called by:
String[] array = Strings.split("a b c d e", Character::isWhitespace);
s - the string to be splitspaceTest - the space test functionNullPointerException - if the input string is nullpublic static String[] split(String s, int start, int end, IntPredicate spaceTest)
IntPredicate function.s - the string to be splitstart - the start index of the portion to be examinedend - the end index (exclusive) of the portion to be examinedspaceTest - the space test functionNullPointerException - if the input string is nullIndexOutOfBoundsException - if start or end is invalidpublic static String[] split(String s1, String s2)
s1 - the string to be splits2 - the separatorNullPointerException - if either string is nullpublic static String[] split(String s, char separator)
s - the string to be splitseparator - the separatorNullPointerException - if the input string is nullpublic static String[] split(String s, char separator, boolean skipEmpty, IntPredicate spaceTest)
s - the string to be splitseparator - the separatorskipEmpty - if true, ignore zero-length items (possibly after trimming)spaceTest - if not null, use to trim spaces off both ends of each itemNullPointerException - if the input string is nullpublic static String[] split(String s, int start, int end, char separator, boolean skipEmpty, IntPredicate spaceTest)
s - the string to be splitstart - the start index of the portion to be examinedend - the end index (exclusive) of the portion to be examinedseparator - the separatorskipEmpty - if true, ignore zero-length items (possibly after trimming)spaceTest - if not null, use to trim spaces off both ends of each itemNullPointerException - if the input string is nullIndexOutOfBoundsException - if start or end is invalidpublic static <E> String join(Iterable<E> collection)
E - class of collection itemcollection - the collection (strictly speaking, an Iterable)public static <E> String join(Iterator<E> it)
Iterator.public static <E> String join(Enumeration<E> e)
Enumeration.E - class of collection iteme - the EnumerationEnumeration has no members)public static <E> String join(E[] array)
E - class of array itemarray - the arraypublic static <E> String join(Iterable<E> collection, char separator)
E - class of collection itemcollection - the collection (strictly speaking, an Iterable)separator - the separatorpublic static <E> String join(Iterator<E> it, char separator)
Iterator, with the specified
character separator.public static <E> String join(Enumeration<E> e, char separator)
Enumeration, with the
specified character separator.E - class of collection iteme - the Enumerationseparator - the separatorEnumeration has no members)public static <E> String join(E[] array, char separator)
E - class of array itemarray - the arrayseparator - the separatorpublic static <E> String join(Iterable<E> collection, String separator)
E - class of collection itemcollection - the collection (strictly speaking, an Iterable)separator - the separatorpublic static <E> String join(Iterator<E> it, String separator)
Iterator, with the specified
string separator.public static <E> String join(Enumeration<E> e, String separator)
Enumeration, with the
specified string separator.E - class of collection iteme - the Enumerationseparator - the separatorEnumeration has no members)public static <E> String join(E[] array, String separator)
E - class of array itemarray - the arrayseparator - the separatorpublic static String escape(String s, CharMapper mapper)
CharMapper instance. If the string contains no characters to be mapped,
the original string is returned unmodified.s - the string to be convertedmapper - the CharMapper instancepublic static CharSequence escape(CharSequence s, CharMapper mapper)
CharSequence with their mapped equivalents, as
specified in the provided CharMapper instance. If the sequence contains no
characters to be mapped, the original sequence is returned unmodified.s - the CharSequence to be convertedmapper - the CharMapper instancepublic static void appendEscaped(Appendable a, CharSequence s, int index, int end, CharMapper mapper) throws IOException
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance.a - the Appendable (e.g. a StringBuilder)s - the source CharSequenceindex - the start index within the sourceend - the end index within the sourcemapper - the CharMapperIOException - if thrown by the Appendablepublic static void appendEscaped(Appendable a, CharSequence s, CharMapper mapper) throws IOException
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance.a - the Appendable (e.g. a StringBuilder)s - the source CharSequencemapper - the CharMapperIOException - if thrown by the Appendablepublic static String escapeUTF16(String s, CharMapper mapper)
CharMapper instance. Surrogate sequences are converted to Unicode
code points before mapping. If the string contains no characters to be mapped, the
original string is returned unmodified.s - the UTF16 string to be convertedmapper - the CharMapper instancepublic static CharSequence escapeUTF16(CharSequence s, CharMapper mapper)
CharSequence with their mapped equivalents, as
specified in the provided CharMapper instance. Surrogate sequences are converted
to Unicode code points before mapping. If the sequence contains no characters to be
mapped, the original sequence is returned unmodified.s - the CharSequence to be convertedmapper - the CharMapper instancepublic static void appendEscapedUTF16(Appendable a, CharSequence s, int index, int end, CharMapper mapper) throws IOException
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. Surrogate sequences are converted
to Unicode code points before mapping.a - the Appendable (e.g. a StringBuilder)s - the source CharSequenceindex - the start index within the sourceend - the end index within the sourcemapper - the CharMapperIOException - if thrown by the Appendablepublic static void appendEscapedUTF16(Appendable a, CharSequence s, CharMapper mapper) throws IOException
Appendable, mapping them to their "escaped" equivalents
specified in the provided CharMapper instance. Surrogate sequences are converted
to Unicode code points before mapping.a - the Appendable (e.g. a StringBuilder)s - the source CharSequencemapper - the CharMapperIOException - if thrown by the Appendablepublic static String unescape(String s, CharUnmapper unmapper)
s - the string to be convertedunmapper - an instance of the CharUnmapper class, which will perform
the actual escape sequence mappingpublic static CharSequence unescape(CharSequence s, CharUnmapper unmapper)
CharSequence for escape sequences and replace them by the original
characters. For example, in Java code the backslash character indicates the start of an
escape sequence representing a character that may not appear in its raw form in a string.s - the CharSequence to be convertedunmapper - an instance of the CharUnmapper class, which will perform
the actual escape sequence mappingCharSequencepublic static String toUTF16(int codePoint)
codePoint - the Unicode code pointpublic static String toUTF16(int[] codePoints)
codePoints - the Unicode code pointspublic static void appendUTF16(Appendable a, int codePoint) throws IOException
Appendable. Code points outside the BMP are
appended as surrogate sequences.a - the Appendable (e.g. a StringBuilder)codePoint - the Unicode code pointIOException - if thrown by the Appendablepublic static byte[] toUTF8(String str)
str - the stringpublic static String fromUTF8(byte[] bytes)
bytes - the byte arrayIllegalArgumentException - if the byte array is null, or if the
byte array contains an invalid UTF-8 sequencepublic static byte[] toUTF8(String str, int start, int end)
str - the stringstart - the start indexend - the end indexIllegalArgumentException - if the string is null, or if the string
contains an invalid UTF-16 sequencepublic static void appendUTF8(ByteArrayBuilder bab, int codepoint)
ByteArrayBuilder as UTF-8.bab - the ByteArrayBuildercodepoint - the codepointpublic static String fromUTF8(ByteBuffer byteBuffer)
ByteBuffer from UTF-8 encoding to a UTF-16 string.byteBuffer - the ByteBufferIllegalArgumentException - if the byte array is null, if the start
or end index is invalid, or if the byte array contains an invalid UTF-8
sequencepublic static String fromUTF8(ByteBuffer[] byteBuffers)
ByteBuffers from UTF-8 encoding to a UTF-16 string.byteBuffers - the ByteBuffer arrayIllegalArgumentException - if the byte array is null, if the start
or end index is invalid, or if the byte array contains an invalid UTF-8
sequencepublic static String fromUTF8(Iterator<Byte> byteIterator)
Iterator from UTF-8 encoding to a UTF-16 string.byteIterator - an Iterator over a sequence of bytesIllegalArgumentException - if the byte array is null, if the start
or end index is invalid, or if the byte array contains an invalid UTF-8
sequencepublic static String fromUTF8(byte[] bytes, int start, int end)
bytes - the byte arraystart - the start indexend - the end indexIllegalArgumentException - if the byte array is null, if the start
or end index is invalid, or if the byte array contains an invalid UTF-8
sequencepublic static String toHex(CharSequence s)
CharSequence to hexadecimal.s - the CharSequenceIllegalArgumentException - if the CharSequence is nullpublic static String toHex(CharSequence s, char separator)
CharSequence to hexadecimal, with a separator between bytes for easier
reading.s - the CharSequenceseparator - the separatorIllegalArgumentException - if the CharSequence is nullpublic static String toHex(byte[] bytes)
bytes - the byte arrayIllegalArgumentException - if the byte array is nullpublic static String toHex(byte[] bytes, char separator)
bytes - the byte arrayseparator - the separatorIllegalArgumentException - if the byte array is nullpublic static String toHex(byte b)
b - the bytepublic static String toHex(char ch)
ch - the characterpublic static String toHex(int i)
i - the integerpublic static String toHex(long n)
n - the numberpublic static void appendHex(Appendable a, byte b) throws IOException
Appendable.a - the Appendableb - the byteIOException - if thrown by the Appendablepublic static void appendHex(Appendable a, char ch) throws IOException
Appendable.a - the Appendablech - the characterIOException - if thrown by the Appendablepublic static void appendHex(Appendable a, int i) throws IOException
Appendable.a - the Appendablei - the numberIOException - if thrown by the Appendablepublic static void appendHex(Appendable a, int i, int digits) throws IOException
Appendable, specifying the number of
output digits.a - the Appendablei - the numberdigits - the number of digitsIOException - if thrown by the Appendablepublic static void appendHex(Appendable a, long n) throws IOException
Appendable.a - the Appendablen - the numberIOException - if thrown by the Appendablepublic static void appendHex(Appendable a, long n, int digits) throws IOException
Appendable, specifying the number of
output digits.a - the Appendablen - the numberdigits - the number of digitsIOException - if thrown by the Appendablepublic static int convertToInt(CharSequence text, int start, int end)
CharSequence to an int.text - the CharSequencestart - the start offset of the digitsend - the end offset of the digitsintIndexOutOfBoundsException - if start or end invalidNumberFormatException - if any digit is invalid, or if the value is too big for an
intpublic static long convertToLong(CharSequence text, int start, int end)
CharSequence to a long.text - the CharSequencestart - the start offset of the digitsend - the end offset of the digitslongIndexOutOfBoundsException - if start or end invalidNumberFormatException - if any digit is invalid, or if the value is too big for a
longpublic static int convertDecDigit(char ch)
ch - the decimal digitNumberFormatException - if the digit is not validpublic static int convertHexToInt(CharSequence text, int start, int end)
CharSequence to an int.text - the CharSequencestart - the start offset of the digitsend - the end offset of the digitsintIndexOutOfBoundsException - if start or end invalidNumberFormatException - if any digit is invalid, or if the value is too big for an
intpublic static long convertHexToLong(CharSequence text, int start, int end)
CharSequence to a long.text - the CharSequencestart - the start offset of the digitsend - the end offset of the digitslongIndexOutOfBoundsException - if start or end invalidNumberFormatException - if any digit is invalid, or if the value is too big for a
longpublic static int convertHexDigit(char ch)
ch - the hexadecimal digitNumberFormatException - if the digit is not validpublic static boolean multiWildcardCompare(String pattern, CharSequence target)
? for single character matches and * for
multiple character matches) separated by vertical bar (logical or) characters. The
comparison returns true if any of the patterns match the target.pattern - the pattern string as described abovetarget - the target CharSequence (String, StringBuilder,
StringBuffer etc.)true if the target string matches the patternwildcardCompare(String, int, int, CharSequence)public static boolean wildcardCompare(String pattern, CharSequence target)
true if the target string
matches the pattern, according to the common wildcard rules:
*”?”pattern - the pattern string, which may include wildcard characters as described
abovetarget - the target CharSequence (String, StringBuilder,
StringBuffer etc.)true if the target string matches the patternpublic static boolean wildcardCompare(String pattern, int patIndex, int patEnd, CharSequence target)
true if the target string
matches the pattern, according to the common wildcard rules:
*”?”String.substring(int, int) operation.pattern - the pattern string, which may include wildcard characters as
described abovepatIndex - the start index within the pattern stringpatEnd - the end index within the pattern stringtarget - the target CharSequence (String,
StringBuilder, StringBuffer etc.)true if the target string matches the patternpublic static String trim(String s, IntPredicate test)
IntPredicate function.s - the string to be trimmedtest - the test functionNullPointerException - if either argument is nullpublic static String trimLeading(String s, IntPredicate test)
IntPredicate function.s - the string to be trimmedtest - the test functionNullPointerException - if either argument is nullpublic static String trimTrailing(String s, IntPredicate test)
IntPredicate function.s - the string to be trimmedtest - the test functionNullPointerException - if either argument is nullpublic static CharSequence trim(CharSequence cs, IntPredicate test)
CharSequence, where those characters
match a supplied IntPredicate function.cs - the CharSequence to be trimmedtest - the test functionCharSequenceNullPointerException - if either argument is nullpublic static CharSequence trimLeading(CharSequence cs, IntPredicate test)
CharSequence, where those characters match a supplied IntPredicate
function.cs - the CharSequence to be trimmedtest - the test functionCharSequenceNullPointerException - if either argument is nullpublic static CharSequence trimTrailing(CharSequence cs, IntPredicate test)
CharSequence, where those characters match a supplied IntPredicate
function.cs - the CharSequence to be trimmedtest - the test functionCharSequenceNullPointerException - if either argument is nullpublic static String trim(String s)
Character.isWhitespace(char).s - the string to be trimmedNullPointerException - if the input string is nullpublic static String trimLeading(String s)
Character.isWhitespace(char).s - the string to be trimmedNullPointerException - if the input string is nullpublic static String trimTrailing(String s)
Character.isWhitespace(char).s - the string to be trimmedNullPointerException - if the input string is nullpublic static CharSequence trim(CharSequence cs)
CharSequence, where white space is determined by
Character.isWhitespace(char).cs - the CharSequence to be trimmedCharSequenceNullPointerException - if the input CharSequence is nullpublic static CharSequence trimLeading(CharSequence cs)
CharSequence, where white space is determined by
Character.isWhitespace(char).cs - the CharSequence to be trimmedCharSequenceNullPointerException - if the input CharSequence is nullpublic static CharSequence trimTrailing(CharSequence cs)
CharSequence, where white space is determined by
Character.isWhitespace(char).cs - the CharSequence to be trimmedCharSequenceNullPointerException - if the input CharSequence is nullpublic static String trimUTF16(String s, IntPredicate test)
IntPredicate function.s - the string to be trimmedtest - the test functionNullPointerException - if either argument is nullpublic static String strip(String s, IntPredicate test)
IntPredicate function.s - the string to be strippedtest - the test functionNullPointerException - if either argument is nullpublic static CharSequence strip(CharSequence cs, IntPredicate test)
CharSequence, where those characters match a supplied
IntPredicate function.cs - the CharSequence to be strippedtest - the test functionCharSequenceNullPointerException - if either argument is nullpublic static String stripUTF16(String s, IntPredicate test)
IntPredicate function.s - the string to be strippedtest - the test functionNullPointerException - if either argument is nullpublic static StringBuilder build()
StringBuilder. Supports the idiom:
String str = Strings.build().append('(').append(n).append(')').toString();
StringBuilderpublic static StringBuilder build(CharSequence cs)
StringBuilder. Supports the idiom:
String str = Strings.build("(").append(n).append(')').toString();
cs - the initial contentsStringBuilderpublic static String toIdentifier(int i)
i - the number to convertpublic static void appendInt(Appendable a, int i) throws IOException
int to an Appendable. This method outputs the digits left to
right, avoiding the need to allocate a separate buffer.a - the Appendablei - the intIOException - if thrown by the Appendablepublic static void appendPositiveInt(Appendable a, int i) throws IOException
int to an Appendable. This method outputs the digits
left to right, avoiding the need to allocate a separate buffer.a - the Appendablei - the intIOException - if thrown by the Appendablepublic static void appendLong(Appendable a, long n) throws IOException
long to an Appendable. This method outputs the digits left to
right, avoiding the need to allocate a separate buffer.a - the Appendablen - the longIOException - if thrown by the Appendablepublic static void appendPositiveLong(Appendable a, long n) throws IOException
long to an Appendable. This method outputs the digits
left to right, avoiding the need to allocate a separate buffer.a - the Appendablen - the longIOException - if thrown by the Appendablepublic static void append2Digits(Appendable a, int i) throws IOException
int to an Appendable as two decimal digits. There is often a
requirement to output a number as 2 digits, for example the cents value in dollars and
cents, or hours, minutes and seconds in a time string. Note that there is no range check
on the input value; to use this method in cases where the value is not guaranteed to be
in the range 00-99, use:
Strings.append2Digits(a, Math.abs(i) % 100);
a - the Appendablei - the intIOException - if thrown by the Appendablepublic static void append3Digits(Appendable a, int i) throws IOException
int to an Appendable as three decimal digits. There is less
frequently a requirement to output a number as 3 digits, for example the milliseconds in
a time string. Note that there is no range check on the input value; to use this method
in cases where the value is not guaranteed to be in the range 000-999, use:
Strings.append3Digits(a, Math.abs(i) % 1000);
a - the Appendablei - the intIOException - if thrown by the AppendableCopyright © 2020. All rights reserved.