public final class StringUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
StringUtil.Joiner<T>
Transform a Object (T) to String.
|
| Modifier and Type | Field and Description |
|---|---|
static StringUtil.Joiner<java.lang.String> |
STRING_JOINER
This Joiner instance converts String to Strings by doing nothing
|
| Constructor and Description |
|---|
StringUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
camelCase(java.lang.String s)
Converts a string into camelcase
|
static java.lang.String |
camelCase(java.lang.String str,
java.lang.String separator)
Converts a string into camelcase
|
static java.lang.String |
camelCase(java.lang.String str,
java.lang.String separator,
boolean firstUpper)
Converts a string into camelcase
|
static boolean |
charsEqualIgnoreCase(char a,
char b)
Checks if two cars equals ignoring the case.
|
static boolean |
containsDouble(java.lang.String str,
char letter)
Checks if a letter is thwo times in string
|
static boolean |
containsIgnoreCase(java.lang.String where,
java.lang.String what)
Checks if a string contains another string.
|
static boolean |
containsTrimmed(java.lang.String str)
Checks if a
trim() will change something |
static boolean |
endsWithChar(java.lang.String str,
char suffix)
Checks if two cars equals ignoring the case.
|
static boolean |
endsWithIgnoreCase(java.lang.String text,
java.lang.String suffix)
Checks if a string ends with a string ignoring the case
|
static java.lang.String |
format(java.lang.String string,
java.lang.Object... args)
Inserts objects into a String
|
static java.lang.String |
fromException(java.lang.Throwable throwable)
Deprecated.
instead use
ExceptionUtil.toString(Throwable) |
static char |
getLast(java.lang.String str)
Gets the last char of a string
|
static java.lang.String |
getLast(java.lang.String str,
int places)
Gets the last n chars
|
static java.lang.String |
getLastSplit(java.lang.String str,
java.lang.String separator)
Returns the last split index of a string
Example:
getLastSplit("hallo my name is david", " ") == "david"
|
static java.lang.String |
humanReadableBytes(long bytes)
Returns the number of bytes formatted
|
static int |
indexOfIgnoreCase(java.lang.String where,
java.lang.String what,
int fromIndex)
Get the index of string in a string.
|
static boolean |
isDouble(java.lang.String str)
Checks if a String could be parsed as a double
|
static boolean |
isEmpty(java.lang.CharSequence str)
Checks if a CharSequence is empty or null
|
static boolean |
isEmptyDeep(java.lang.CharSequence str)
Checks if a CharSequence is empty or null or has only whitespaces
|
static boolean |
isFloat(java.lang.String str)
Checks if a String could be parsed as a float
|
static boolean |
isInteger(java.lang.String str)
Checks if a String could be parsed as a integer
|
static boolean |
isLong(java.lang.String str)
Checks if a String could be parsed as a long
|
static boolean |
isNoSpecialSpace(char ch)
Deprecated.
|
static boolean |
isNoWhiteSpace(char ch)
Deprecated.
use
Character.isWhitespace(char) |
static boolean |
isWhiteSpace(char ch)
Deprecated.
use
Character.isWhitespace(char) |
static java.lang.String |
join(java.lang.Iterable<java.lang.String> iterable)
Combines multiple strings with a comma
|
static java.lang.String |
join(java.lang.Iterable<java.lang.String> iterable,
java.lang.String separator)
Combines multiple strings
|
static <T> java.lang.String |
join(java.lang.Iterable<T> iterable,
StringUtil.Joiner<T> joiner)
Combines multiple objects with a specific Joiner.
|
static <T> java.lang.String |
join(java.lang.Iterable<T> iterable,
StringUtil.Joiner<T> joiner,
java.lang.String separator)
Combines multiple objects with a specific Joiner.
|
static java.lang.String |
join(java.lang.String[] array)
Combines multiple strings with a comma
|
static java.lang.String |
join(java.lang.String[] array,
java.lang.String separator)
Combines multiple strings
|
static <T> java.lang.String |
join(T[] array,
StringUtil.Joiner<T> joiner)
Combines multiple objects with a specific Joiner.
|
static <T> java.lang.String |
join(T[] array,
StringUtil.Joiner<T> joiner,
java.lang.String separator)
Combines multiple objects with a specific Joiner.
|
static int |
lastIndexOf(java.lang.String str,
char c,
int start,
int end)
Get the index of a char in String.
|
static void |
removeEnd(java.lang.StringBuilder builder,
java.lang.String end)
Removed the end of a StringBuilder
|
static void |
removeEnd(java.lang.StringBuilder builder,
java.lang.String end,
boolean onlyPossible)
Removed the end of a StringBuilder
|
static java.lang.String |
removeEnd(java.lang.String str,
java.lang.String end)
Removed the end of a string if it is the end
|
static java.lang.String |
removeLast(java.lang.String str,
int places)
Removes the end of a string
|
static java.lang.String |
repeat(java.lang.String str,
int times)
Repeats a string n times
|
static boolean |
startsWithIgnoreCase(java.lang.String str,
java.lang.String prefix)
Checks if a string starts with a string ignoring the case
|
static double |
toDouble(java.lang.String str)
Deprecated.
use
Double.valueOf(String) |
static float |
toFloat(java.lang.String str)
Deprecated.
use
Float.valueOf(String) |
static long |
toLong(java.lang.String str)
Deprecated.
use
Long.valueOf(String) |
public static final StringUtil.Joiner<java.lang.String> STRING_JOINER
public static boolean isEmpty(java.lang.CharSequence str)
str - the string to checkpublic static boolean isEmptyDeep(java.lang.CharSequence str)
str - the string to checkpublic static java.lang.String humanReadableBytes(long bytes)
bytes - the number of bytespublic static boolean isNoWhiteSpace(char ch)
Character.isWhitespace(char)@Deprecated public static boolean isNoSpecialSpace(char ch)
@Deprecated public static boolean isWhiteSpace(char ch)
Character.isWhitespace(char)@Deprecated public static java.lang.String fromException(java.lang.Throwable throwable)
ExceptionUtil.toString(Throwable)public static boolean isFloat(java.lang.String str)
str - the string to check@Deprecated public static float toFloat(java.lang.String str)
Float.valueOf(String)public static boolean isDouble(java.lang.String str)
str - the string to checkpublic static double toDouble(java.lang.String str)
Double.valueOf(String)public static boolean isLong(java.lang.String str)
str - the string to checkpublic static long toLong(java.lang.String str)
Long.valueOf(String)public static boolean isInteger(java.lang.String str)
str - the string to checkpublic static java.lang.String join(java.lang.Iterable<java.lang.String> iterable)
iterable - the strings that should be combinedpublic static java.lang.String join(java.lang.Iterable<java.lang.String> iterable,
java.lang.String separator)
iterable - the strings that should be combinedseparator - separator the stringspublic static java.lang.String join(java.lang.String[] array,
java.lang.String separator)
array - the strings that should be combinedseparator - separator the stringspublic static java.lang.String join(java.lang.String[] array)
array - the strings that should be combinedpublic static <T> java.lang.String join(java.lang.Iterable<T> iterable,
StringUtil.Joiner<T> joiner)
iterable - the strings that should be combinedpublic static <T> java.lang.String join(java.lang.Iterable<T> iterable,
StringUtil.Joiner<T> joiner,
java.lang.String separator)
iterable - the strings that should be combinedseparator - separator the stringspublic static <T> java.lang.String join(T[] array,
StringUtil.Joiner<T> joiner)
array - the strings that should be combinedpublic static <T> java.lang.String join(T[] array,
StringUtil.Joiner<T> joiner,
java.lang.String separator)
array - the strings that should be combinedseparator - separator the stringspublic static java.lang.String format(java.lang.String string,
java.lang.Object... args)
string - the raw stringargs - the objects you want to insertpublic static boolean charsEqualIgnoreCase(char a,
char b)
public static boolean endsWithChar(java.lang.String str,
char suffix)
public static boolean startsWithIgnoreCase(java.lang.String str,
java.lang.String prefix)
str - the string that should be checkedprefix - the string that str starts withpublic static boolean endsWithIgnoreCase(java.lang.String text,
java.lang.String suffix)
text - the string that should be checkedsuffix - the string that str ends withpublic static int lastIndexOf(java.lang.String str,
char c,
int start,
int end)
str - the string that should be checkedc - the char we want to findstart - at what position should we start the stringend - at what position should we end the stringpublic static boolean containsIgnoreCase(java.lang.String where,
java.lang.String what)
where - the sourcewhat - the string you want to find in wherepublic static int indexOfIgnoreCase(java.lang.String where,
java.lang.String what,
int fromIndex)
what - the string that should be checkedwhere - the sourcewhat - the string you want to find the index of in wherefromIndex - tarting pointpublic static java.lang.String removeLast(java.lang.String str,
int places)
str - the string from what you want to remove the endplaces - the amount of chars you want to removepublic static boolean containsDouble(java.lang.String str,
char letter)
str - sourceletter - the letter you want to check forpublic static java.lang.String camelCase(java.lang.String s)
public static java.lang.String camelCase(java.lang.String str,
java.lang.String separator)
separator - the separator that should be used.
For example: My-Name-Is-David or My Name Is Davidpublic static java.lang.String camelCase(java.lang.String str,
java.lang.String separator,
boolean firstUpper)
separator - the separator that should be used.
For example: My-Name-Is-David or My Name Is Davidpublic static java.lang.String getLastSplit(java.lang.String str,
java.lang.String separator)
str - the sourcepublic static java.lang.String repeat(java.lang.String str,
int times)
str - the string you want to repeattimes - the number of times you wan to repeat the stringpublic static java.lang.String removeEnd(java.lang.String str,
java.lang.String end)
str - the source stringend - the end you want to removepublic static void removeEnd(java.lang.StringBuilder builder,
java.lang.String end)
builder - the source StringBuilderend - the end you want to removepublic static void removeEnd(java.lang.StringBuilder builder,
java.lang.String end,
boolean onlyPossible)
builder - the source StringBuilderend - the end you want to removeonlyPossible - is it possible that the source is long then the end AND is not the endpublic static java.lang.String getLast(java.lang.String str,
int places)
str - the sourceplaces - the number of charspublic static char getLast(java.lang.String str)
str - the stringpublic static boolean containsTrimmed(java.lang.String str)
trim() will change somethingstr - the stringtrim()String.trim()