public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static NumberFormat |
DOUBLE_FORMAT |
static NumberFormat |
INTEGER_FORMAT |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static List<String> |
charSequenceToStringList(CharSequence sequence)
Converts the specified character sequence to a list strings, where each character of the sequence is
represented as a single string object.
|
static String |
concatWithOperator(String leftPart,
String rightPart,
String operator)
Concatenates two expressions with an operator if both are not empty.
|
static String |
concatWithOperator(String leftPart,
String rightPart,
String operator,
String leftBracket,
String rightBracket)
Concatenates two expressions with an operator if both are not empty.
|
static boolean |
containsWhitespace(CharSequence sequence)
Tests if the specified character sequence does not contain any whitespace.
|
static String |
convertCamelCase(String text,
String separator)
Converts a camel case keyword to a string with the specified separator where all characters are in lower case.
|
static CharSequence |
cutEnd(CharSequence sequence,
int length)
Cuts off the specified number of characters from the end of the specified character sequence.
|
static String |
cutEnd(String sequence,
int length)
Cuts off the specified number of characters from the end of the specified string.
|
static boolean |
endsWith(CharSequence sequence,
char terminalSymbol)
Tests whether a character sequence ends with a specified character.
|
static String |
firstCharToLowerCase(String text) |
static String |
firstCharToUpperCase(String text) |
static int |
indexOfWhiteSpace(CharSequence sequence)
Returns the first index of any whitespace character.
|
static int |
indexOfWhiteSpace(CharSequence sequence,
int fromIndex)
Returns the first index of any whitespace character.
|
static String |
invert(CharSequence s) |
static boolean |
isNewLineChar(char c)
Checks if the specified character is a new line character
|
static char |
lastChar(CharSequence sequence)
Returns the last character of the specified sequence.
|
static void |
renameRepeatedEntries(List<String> list) |
static void |
renameRepeatedEntries(String[] array) |
static String |
repeat(CharSequence element,
int count) |
public static final NumberFormat DOUBLE_FORMAT
public static final NumberFormat INTEGER_FORMAT
public StringUtils()
public static String invert(CharSequence s)
public static String repeat(CharSequence element, int count)
public static void renameRepeatedEntries(String[] array)
public static void renameRepeatedEntries(List<String> list)
public static String concatWithOperator(String leftPart, String rightPart, String operator, String leftBracket, String rightBracket)
Concatenates two expressions with an operator if both are not empty.
Example:
concatWithOperator("A", "B", " + ", "(", ")")
would return
"(A + B)".
concatWithOperator("A", "", " + ", "(", ")")
would return
"A".
leftPart
- the left expressionrightPart
- the right expressionoperator
- the operator (including white spaces if necessary)leftBracket
- the left bracket to be used (e.g. "{")rightBracket
- the right bracket to be used (e.g. "}")public static String concatWithOperator(String leftPart, String rightPart, String operator)
leftPart
- the left expressionrightPart
- the right expressionoperator
- the operator (including white spaces if necessary)concatWithOperator(String, String, String, String, String)
public static String firstCharToLowerCase(String text)
public static String firstCharToUpperCase(String text)
public static String convertCamelCase(String text, String separator)
Example: anExampleKeyword
would be converted to an-example-keyword
and A
to a
.
text
- the string to be convertedseparator
- the separator to be insertedpublic static boolean isNewLineChar(char c)
c
- the character to be testedtrue
if c
is either '\n'
or '\r'
, false
otherwise.public static int indexOfWhiteSpace(CharSequence sequence)
sequence
- the character sequence to be searchedCharacter.isWhitespace(char)
)
or -1 if the sequence does not contain any whitespacepublic static int indexOfWhiteSpace(CharSequence sequence, int fromIndex)
sequence
- the character sequence to be searchedfromIndex
- the index to start the searchCharacter.isWhitespace(char)
)
at or after fromIndex
or -1 if the sequence does not contain any whitespace behind that
positionpublic static boolean containsWhitespace(CharSequence sequence)
Note this method will return false
, if an empty sequence (""
) is specified.
sequence
- the character sequence to be testedtrue
if the sequence contains no whitespace or false
otherwiseNullPointerException
- if sequence
is null
public static boolean endsWith(CharSequence sequence, char terminalSymbol)
sequence
- the sequence to be testedterminalSymbol
- the expected last character of the sequencetrue
if the sequence is at least one character long and last character is equal to
terminalSymbol
, false
otherwise.public static CharSequence cutEnd(CharSequence sequence, int length)
If length
is higher than the length of sequence
an empty string is returned.
sequence
- the character sequence to be cutlength
- the number of characters to be removed from the endpublic static String cutEnd(String sequence, int length)
If length
is higher than the length of sequence
an empty string is returned.
sequence
- the string to be cutlength
- the number of characters to be removed from the endpublic static char lastChar(CharSequence sequence)
sequence
- the character sequence to extract the last character fromIllegalArgumentException
- if sequence
is not at least one character longpublic static List<String> charSequenceToStringList(CharSequence sequence)
sequence
- the sequence to be converted