Modifier and Type | Field and Description |
---|---|
static Map<String,BigDecimal> |
BINARY_UNITS
Map of binary units to their factor
K : 1024
M : 1024 * 1024
G : 1024 * 1024 * 1024
... |
static Map<String,Integer> |
DECIMAL_UNITS
Map of decimal units to their power of ten
...
|
static Charset |
DEFAULT_CHARSET
Constant UTF-8 for usage as default char set.
|
static Locale |
DEFAULT_LOCALE
Constant locale as default locale where no language and country is required.
|
static String |
NEW_LINE
Constant
"\n" for output. |
Modifier and Type | Method and Description |
---|---|
static int |
compareIgnoreCaseAscii(CharSequence first,
CharSequence second)
Compares two strings, ignoring case differences in the ASCII range.
|
static boolean |
containsIgnoreCase(CharSequence string,
CharSequence substring)
Tests if
value contains substring , ignoring case
considerations. |
static boolean |
containsIgnoreCaseAscii(CharSequence string,
CharSequence substring)
Tests if
value contains substring , ignoring case
considerations in the ACII range. |
static boolean |
endsWithIgnoreCase(CharSequence value,
CharSequence suffix)
Tests if
value ends with the specified suffix, ignoring case
considerations. |
static boolean |
endsWithIgnoreCaseAscii(CharSequence value,
CharSequence suffix)
Tests if
value ends with the specified suffix, ignoring case
considerations in the ASCII range. |
static boolean |
equalsIgnoreCaseAscii(CharSequence first,
CharSequence second)
Compares
first to second , ignoring case considerations in the
ASCII range. |
static boolean |
find(CharSequence input,
Pattern pattern)
Tells whether or not a subsequence
input matches pattern . |
static String |
format(String format,
Object... arguments)
Returns a formatted string using the specified format string and
arguments . |
static int |
indexOfIgnoreCase(CharSequence string,
CharSequence substring)
Returns the index within
string of the first occurrence of
substring , ignoring case considerations. |
static int |
indexOfIgnoreCase(CharSequence string,
CharSequence substring,
int fromIndex)
Returns the index within
string of the first occurrence of
substring , ignoring case considerations, starting at the specified
index. |
static int |
indexOfIgnoreCaseAscii(CharSequence string,
CharSequence substring)
Returns the index within
string of the first occurrence of
substring , ignoring case considerations in the ASCII range. |
static int |
indexOfIgnoreCaseAscii(CharSequence string,
CharSequence substring,
int fromIndex)
Returns the index within
string of the first occurrence of
substring , ignoring case considerations in the ASCII range, starting
at the specified index. |
static boolean |
isBlank(CharSequence value)
Returns
true if value consists of whitespace only or equals
null . |
static boolean |
matches(CharSequence input,
Pattern pattern)
Tells whether or not
input matches pattern . |
static Comparator<String> |
numericTextComparator(boolean caseInsensitive)
A
Comparator that orders alpha numeric strings in natural
order, either case sensitive or case insensitive. |
static BigInteger |
parseBinaryUnit(CharSequence binaryValue)
Parses
binaryValue as binary value with
optional sign,
optional fraction
and optional binary unit (case insensitive matching). |
static BigDecimal |
parseDecimalUnit(CharSequence decimalValue)
Parses
decimalValue as decimal value with
optional sign,
optional fraction
and optional decimal unit (case insensitive matching - where possible). |
static String |
replaceAll(CharSequence input,
Pattern pattern,
String replacement)
Replaces every subsequence of
input that matches pattern with
replacement . |
static String |
replaceFirst(CharSequence input,
Pattern pattern,
String replacement)
Replaces the first subsequence of
input that matches pattern
with replacement . |
static boolean |
startsWithIgnoreCase(CharSequence value,
CharSequence prefix)
Tests if
value starts with prefix ignoring case
considerations. |
static boolean |
startsWithIgnoreCase(CharSequence value,
CharSequence prefix,
int offset)
Tests if the substring of
value beginning at offset starts
with prefix , ignoring case considerations. |
static boolean |
startsWithIgnoreCaseAscii(CharSequence value,
CharSequence prefix)
Tests if
value starts with the specified prefix, ignoring case
considerations in the ASCII range. |
static boolean |
startsWithIgnoreCaseAscii(CharSequence value,
CharSequence prefix,
int offset)
Tests if the substring of
value beginning at the specified index
starts with the specified prefix, ignoring case considerations in the ASCII
range. |
static String |
toLowerCaseAscii(CharSequence value)
Converts all of the ASCII upper case characters in
value to lower
case. |
static String |
toLowerCaseNeutral(String value)
Converts all of the characters in
value to lower case using
DEFAULT_LOCALE . |
static String |
toTitleCaseNeutral(String value)
Converts
value to title case by converting its first character using
Character.toTitleCase(char) and following to lower case using
DEFAULT_LOCALE . |
static String |
toUpperCaseAscii(CharSequence value)
Converts all of the ASCII lower case characters in
value to upper
case. |
static String |
toUpperCaseNeutral(String value)
Converts all of the characters in
value to upper case using
DEFAULT_LOCALE . |
static String |
trimEnd(CharSequence value)
Returns a string similar to
value , but with any trailing whitespace
removed. |
static String |
trimStart(CharSequence value)
Returns a string similar to
value , but with any leading whitespace
removed. |
public static final Map<String,BigDecimal> BINARY_UNITS
K
: 1024
M
: 1024 * 1024
G
: 1024 * 1024 * 1024
public static final Map<String,Integer> DECIMAL_UNITS
m
: -3
k
: 3
M
: 6
public static final Charset DEFAULT_CHARSET
Using Charset.defaultCharset()
leads to unexpected
compatibility problems. While the new Files
API has
been changed to use UTF-8 by default, old and third-party implementations
still depend on the default char set or require a custom char set.
Why shouldn't I use StandardCharsets.UTF_8
directly?
Using StandardCharsets.UTF_8
is bad practice, as it holds
implementation specific information.
public static final Locale DEFAULT_LOCALE
Using Locale.getDefault()
leads to unexpected behavior for technical
formatting operations. Therefore this locale specifies a default value.
The returned value is Locale.ROOT
.
public static final String NEW_LINE
"\n"
for output. Remember to accept "\r\n"
and "\r"
on the input side, too!
Using System.lineSeparator()
leads to files, which cannot (should
not) be transferred between UNIX and Microsoft Windows systems. To avoid
problems, some developers decided to depend on the UNIX line separator only.
Why shouldn't I use "\n"
directly?
Using "\n"
is bad practice, as it holds implementation specific
information.
public static int compareIgnoreCaseAscii(CharSequence first, CharSequence second)
first
- the first string to comparesecond
- the second string to comparefirst
is
greater than, equal to, or less than second
, ignoring case
considerations in the ASCII range.public static boolean containsIgnoreCase(CharSequence string, CharSequence substring)
value
contains substring
, ignoring case
considerations.string
- the string to search insubstring
- the sequence to search fortrue
if value
contains substring
, ignoring
case considerations, else false
public static boolean containsIgnoreCaseAscii(CharSequence string, CharSequence substring)
value
contains substring
, ignoring case
considerations in the ACII range.string
- the string to search insubstring
- the sequence to search fortrue
if value
contains substring
, ignoring
case considerations in the ACII range, else false
public static boolean equalsIgnoreCaseAscii(@Nullable CharSequence first, @Nullable CharSequence second)
first
to second
, ignoring case considerations in the
ASCII range. Two strings are considered equal ignoring case if they are of
the same length and corresponding characters in the two strings are equal
ignoring case in the ASCII range.first
- the first of both strings to comparesecond
- the second of both strings to comparetrue
if first
and second
are considered
equal, ignoring case in the ACII range, else false
public static boolean endsWithIgnoreCase(CharSequence value, CharSequence suffix)
value
ends with the specified suffix, ignoring case
considerations.value
- string to compare againstsuffix
- the suffixtrue
if prefix
is a suffix of the character sequence
represented by value
, ignoring case considerations, else
false
public static boolean endsWithIgnoreCaseAscii(CharSequence value, CharSequence suffix)
value
ends with the specified suffix, ignoring case
considerations in the ASCII range.value
- string to compare againstsuffix
- the suffixtrue
if prefix
is a suffix of the character sequence
represented by value
, ignoring case considerations in the
ASCII range, else false
public static boolean find(CharSequence input, Pattern pattern)
input
matches pattern
.
Use Patterns.find(Pattern, CharSequence)
if you need a matcher.
input
- the input sequence to find the pattern inpattern
- the matching patterntrue
if, and only if, input
matches pattern
public static String format(String format, Object... arguments)
arguments
. In that way this method works similar to
String.format(String, Object...)
.
Here are the differences:
arguments
is empty, no checks and formatting is
performed. format
is returned immediately and without modification.
DEFAULT_LOCALE
is used instead of the systems default
Locale
.
format
.
format
- format stringarguments
- arguments referenced by format specifiers in format
public static int indexOfIgnoreCase(CharSequence string, CharSequence substring)
string
of the first occurrence of
substring
, ignoring case considerations.string
- the string to search insubstring
- the substring to search forsubstring
, ignoring case
considerations, or -1
if there is no such occurrencepublic static int indexOfIgnoreCase(CharSequence string, CharSequence substring, int fromIndex)
string
of the first occurrence of
substring
, ignoring case considerations, starting at the specified
index.string
- the string to search insubstring
- the substring to search forfromIndex
- the index from which to start the searchsubstring
, ignoring case
considerations, starting at the specified index, or -1
if
there is no such occurrencepublic static int indexOfIgnoreCaseAscii(CharSequence string, CharSequence substring)
string
of the first occurrence of
substring
, ignoring case considerations in the ASCII range.string
- the string to search insubstring
- the substring to search forsubstring
, ignoring case
considerations in the ASCII range, or -1
if there is no such
occurrencepublic static int indexOfIgnoreCaseAscii(CharSequence string, CharSequence substring, int fromIndex)
string
of the first occurrence of
substring
, ignoring case considerations in the ASCII range, starting
at the specified index.string
- the string to search insubstring
- the substring to search forfromIndex
- the index from which to start the searchsubstring
, ignoring case
considerations in the ASCII range, starting at the specified index,
or -1
if there is no such occurrencepublic static boolean isBlank(@Nullable CharSequence value)
true
if value
consists of whitespace only or equals
null
.
This is an optimized way of value.trim().isEmpty()
.
value
- stringtrue
if value
consists of whitespace only or equals
null
public static boolean matches(CharSequence input, Pattern pattern)
input
matches pattern
.
Use Patterns.matches(Pattern, CharSequence)
if you need a matcher.
input
- the value to matchpattern
- the matching patterntrue
if, and only if, input
matches pattern
public static Comparator<String> numericTextComparator(boolean caseInsensitive)
Comparator
that orders alpha numeric strings in natural
order, either case sensitive or case insensitive. It is appreciated to use
this kind of ordering for user output.
Because numeric values are not deserialized into numeric data types, their length is not limited. Fractions are not supported and will be handled as two separate numeric values.
Numeric values can have a leading plus or minus sign when following a whitespace character or at a strings start.
The following lists some example values to demonstrate the ordering.
This comparator permits null values.
Note that this Comparator does not take locale into account, and will result in an unsatisfactory ordering for certain locales.
caseInsensitive
- true
if comparison should take place case
insensitiveComparator
that orders alpha numeric strings in
natural order, either case sensitive or case insensitive. It
is appreciated to use this kind of ordering for user output.public static BigInteger parseBinaryUnit(CharSequence binaryValue) throws StringParseException
binaryValue
as binary value with
Binary units multiply by 1024. Though strings with fractions can be parsed, the resulting value must not contain a fraction part. Numeric values can be formatted using underscore, just as numeric Java literals can be formatted.
Examples:
Parameter | Calculation | Return Value |
---|---|---|
-2m | -2 * 1024 * 1024 | -2 097 152 |
0 | 0 | |
5.4k | 5.4 * 1024 | 5529.6 -> ArithmeticException |
+5_432 | 5 432 |
binaryValue
- binary stringStringParseException
- on parse failurepublic static BigDecimal parseDecimalUnit(CharSequence decimalValue) throws StringParseException
decimalValue
as decimal value with
Numeric values can be formatted using underscore, just as numeric Java literals can be formatted.
Examples:
Parameter | Return Value |
---|---|
-2m | -0.002 |
0 | 0 |
5.4k | 5 400 |
+5_432 | 5 432 |
decimalValue
- decimal stringStringParseException
- on parse failurepublic static String replaceFirst(CharSequence input, Pattern pattern, String replacement)
input
that matches pattern
with replacement
.
Note that replacement
is not a literal replacement string.
Backslashes (\
) and dollar signs ($
) may be treated
differently. Quote unknown literal replacement strings using
Matcher.quoteReplacement(String)
.
input
- the value to matchpattern
- the matching patternreplacement
- the replacement stringpublic static String replaceAll(CharSequence input, Pattern pattern, String replacement)
input
that matches pattern
with
replacement
.
Note that replacement
is not a literal replacement string.
Backslashes (\
) and dollar signs ($
) may be treated
differently. Quote unknown literal replacement strings using
Matcher.quoteReplacement(String)
.
input
- the value to matchpattern
- the matching patternreplacement
- the replacement stringpublic static boolean startsWithIgnoreCase(CharSequence value, CharSequence prefix)
value
starts with prefix
ignoring case
considerations.value
- string to compare againstprefix
- the prefixtrue
if prefix
is a prefix of value
, ignoring
case considerations, else false
public static boolean startsWithIgnoreCase(CharSequence value, CharSequence prefix, int offset)
value
beginning at offset
starts
with prefix
, ignoring case considerations.value
- string to compare againstprefix
- the prefixoffset
- where to begin looking in value
true
if prefix
is a prefix of the substring of
value
starting at offset
, ignoring case
considerations, else false
. The result is false
if
offset
is negative or greater than the length of
value
.public static boolean startsWithIgnoreCaseAscii(CharSequence value, CharSequence prefix)
value
starts with the specified prefix, ignoring case
considerations in the ASCII range.value
- string to compare againstprefix
- the prefixtrue
if prefix
is a prefix of the character sequence
represented by value
, ignoring case considerations in the
ASCII range, else false
public static boolean startsWithIgnoreCaseAscii(CharSequence value, CharSequence prefix, int offset)
value
beginning at the specified index
starts with the specified prefix, ignoring case considerations in the ASCII
range.value
- string to compare againstprefix
- the prefixoffset
- where to begin looking in value
.true
if prefix
is a prefix of the substring of
value
starting at index offset
, ignoring case
considerations in the ASCII range, else false
. The result is
false
if offset
is negative or greater than the
length of this String
object.public static String toLowerCaseAscii(CharSequence value)
value
to lower
case.value
- string to convertpublic static String toLowerCaseNeutral(String value)
value
to lower case using
DEFAULT_LOCALE
. This method is equivalent to
toLowerCase(Locale.ROOT)
.value
- string to convertpublic static String toTitleCaseNeutral(String value)
value
to title case by converting its first character using
Character.toTitleCase(char)
and following to lower case using
DEFAULT_LOCALE
.value
- string to convertpublic static String toUpperCaseAscii(CharSequence value)
value
to upper
case.value
- string to convertpublic static String toUpperCaseNeutral(String value)
value
to upper case using
DEFAULT_LOCALE
. This method is equivalent to
toUpperCase(Locale.ROOT)
.value
- string to convertpublic static String trimStart(CharSequence value)
value
, but with any leading whitespace
removed.
This method works similar to String.trim()
, though it handles only
the strings start.
Whitespace characters are recognized using
Characters.isAsciiWhitespace(char)
.
value
- valuepublic static String trimEnd(CharSequence value)
value
, but with any trailing whitespace
removed.
This method works similar to String.trim()
, though it handles only
the strings end.
Whitespace characters are recognized using
Characters.isAsciiWhitespace(char)
.
value
- valueCopyright © 2025. All rights reserved.