public class Strings extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
decodeHexNibble(char c)
Helper to decode half of a hexadecimal number from a string.
|
static String |
deleteWhitespace(String str)
Deletes all whitespaces from a String as defined by
Character.isWhitespace(char). |
static byte[] |
getBytesUtf8(String string) |
static boolean |
isBlank(String str)
judge a string has some whitespace at most
|
static boolean |
isEmpty(String str)
judge a string is null or ""
|
static boolean |
isNotBlank(String str) |
static boolean |
isNotEmpty(String str) |
static String |
join(String separator,
Iterable objects) |
static String |
join(String separator,
Iterator objects)
append all objects with the specified separator
|
static String |
newStringUsAscii(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the US-ASCII charset. |
static String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8 charset. |
static String[] |
split(String string,
String separator)
split a string, the returned array is not contains: whitespace, null.
|
static boolean |
substringMatch(CharSequence str,
int index,
CharSequence substring)
Test whether the given string matches the given substring
at the given index.
|
static String |
truncate(String string,
int length)
Get substring from 0 to a specified length
equals: string.substring(0, length)
|
public static boolean isEmpty(String str)
str - the specified stringpublic static boolean isNotEmpty(String str)
public static boolean isBlank(String str)
str - the specified stringpublic static boolean isNotBlank(String str)
public static String truncate(@NonNull String string, int length)
string - a string will be truncatedlength - new string's lengthpublic static String join(@NonNull String separator, @Nullable Iterator objects)
separator - the specified separatorobjects - the dbjects that will be appendpublic static String[] split(@Nullable String string, @Nullable String separator)
public static int decodeHexNibble(char c)
c - The ASCII character of the hexadecimal number to decode.
Must be in the range [0-9a-fA-F].-1 if the character is invalid.public static boolean substringMatch(CharSequence str, int index, CharSequence substring)
str - the original string (or StringBuilder)index - the index in the original string to start matching againstsubstring - the substring to match at the given indexpublic static byte[] getBytesUtf8(String string)
public static String newStringUtf8(byte[] bytes)
String by decoding the specified array of bytes using the UTF-8 charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-8 charset,
or null if the input byte array was null.NullPointerException - Thrown if Charsets.UTF_8 is not initialized, which should never happen since it is
required by the Java platform specification.NullPointerException instead of UnsupportedEncodingExceptionpublic static String newStringUsAscii(byte[] bytes)
String by decoding the specified array of bytes using the US-ASCII charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the US-ASCII charset,
or null if the input byte array was null.NullPointerException - Thrown if Charsets.US_ASCII is not initialized, which should never happen since it is
required by the Java platform specification.NullPointerException instead of UnsupportedEncodingExceptionpublic static String deleteWhitespace(String str)
Deletes all whitespaces from a String as defined by
Character.isWhitespace(char).
StringUtils.deleteWhitespace(null) = null
StringUtils.deleteWhitespace("") = ""
StringUtils.deleteWhitespace("abc") = "abc"
StringUtils.deleteWhitespace(" ab c ") = "abc"
str - the String to delete whitespace from, may be nullnull if null String inputCopyright © 2019. All rights reserved.