public final class StringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static char[] |
ADDITIONAL_ALLOWED_FILE_NAME_SYSTEM_CHARACTERS
Additional characters allowed in file systems.
|
static String |
EMPTY_STRING
Constant for an empty string.
|
static String |
LATIN_ALPHABET_BIG
The latin alphabet with big capitals.
|
static String |
LATIN_ALPHABET_SMALL
The latin alphabet with small capitals.
|
static String |
NEW_LINE
Constant for a line break.
|
static String |
NUMERALS
The numerals.
|
static String |
WHITESPACE
All characters representing whitespace.
|
Modifier | Constructor and Description |
---|---|
private |
StringUtil()
Forbid instances by this private constructor.
|
Modifier and Type | Method and Description |
---|---|
static String |
chop(String text,
int maxLength)
Chops the given text if required.
|
static boolean |
contains(String string,
CharSequence substring)
Checks if the given string contains the substring.
|
static Comparator<String> |
createIgnoreCaseComparator()
Creates a
Comparator that can be used to compute the
equality of two given String s ignoring the case
via String.compareToIgnoreCase(String) . |
static String |
createLine(String text,
int repetitions)
Creates a line which consists of the given text.
|
static boolean |
equalIgnoreWhiteSpace(String first,
String second)
Checks the equality of the given
String s ignoring whitespace. |
static String |
fillString(String text,
char leadingCharacter,
int length)
Fills the given text with the leading character until it has the defined length.
|
static boolean |
isEmpty(String text)
Checks if the
String is empty. |
static boolean |
isTrimmedEmpty(String text)
Checks if the trimmed
String is empty. |
static String |
replaceAll(String text,
char[] toSearch,
char toReplace)
Replaces all occurrences of a search sign with the replacement sign.
|
static boolean |
startsWith(Object obj,
String prefix)
|
static String |
toLowerCase(String text)
Nullpointer save execution of
String.toLowerCase() . |
static String |
toSingleLinedString(String text)
|
static String |
trim(String text)
Nullpointer save execution of
String.trim() |
static String |
trimRight(String text)
Performs a trim only on the right side.
|
public static final String EMPTY_STRING
public static final String NEW_LINE
public static final String LATIN_ALPHABET_BIG
public static final String LATIN_ALPHABET_SMALL
public static final char[] ADDITIONAL_ALLOWED_FILE_NAME_SYSTEM_CHARACTERS
It is important that ':'
is not contained because "::"
is replaced with a '/'
by the JFileChooser
under Mac OS.
public static final String NUMERALS
public static final String WHITESPACE
public static boolean isEmpty(String text)
String
is empty.text
- The text to check.true
= text is null
or empty, false
= text is not empty.public static boolean isTrimmedEmpty(String text)
String
is empty.text
- The text to check.true
= text is null
or trimmed empty, false
= text is not empty.public static String trim(String text)
String.trim()
text
- The text.public static String toLowerCase(String text)
String.toLowerCase()
.text
- The text to convert.null
if the given text is null
.public static Comparator<String> createIgnoreCaseComparator()
Comparator
that can be used to compute the
equality of two given String
s ignoring the case
via String.compareToIgnoreCase(String)
. If both values
are null
also 0
is returned in
Comparator.compare(Object, Object)
. If only one value
is null
Comparator.compare(Object, Object)
will
return a value different to 0
.Comparator
.public static String createLine(String text, int repetitions)
text
- The text to repeate.repetitions
- The number of repetitions.public static boolean contains(String string, CharSequence substring)
Checks if the given string contains the substring.
Attention: The empty string is contained in every string.
string
- The string that should contain the substring.substring
- The substring to check.true
strings are not null
and the string contains the substring, false
if at least one string is null
or the string does not contain the substring.public static String toSingleLinedString(String text)
String
in a single lined String
by replacing all line breaks and tabs with a space.text
- The text to convert.public static String replaceAll(String text, char[] toSearch, char toReplace)
text
- The text to search and replace in.toSearch
- The signs to search.toReplace
- The sign to replace with.String
.public static boolean equalIgnoreWhiteSpace(String first, String second)
String
s ignoring whitespace.public static String fillString(String text, char leadingCharacter, int length) throws IllegalArgumentException
text
- The text to fill.leadingCharacter
- The leading character to use.length
- The length to fill up to.IllegalArgumentException
- If the text is already longer as the given lengthpublic static String trimRight(String text)
text
- The text to trim its right side.public static String chop(String text, int maxLength)
text
- The text to check.maxLength
- The maximal length to ensure.