public class StringUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
arrayToCommaDelimitedString(Object[] strings)
Turns this string array in one comma-delimited string.
|
static String |
arrayToDelimitedString(String delimiter,
Object[] strings)
Turns this string array in one delimited string.
|
static String |
collapseWhitespace(String str)
Replaces all sequences of whitespace by a single blank.
|
static String |
collectionToCommaDelimitedString(Collection<?> collection)
Convenience method to return a Collection as a comma-delimited
String.
|
static String |
collectionToDelimitedString(Collection<?> collection,
String delimiter)
Convenience method to return a Collection as a delimited
String.
|
static int |
countOccurrencesOf(String str,
String token)
Counts the number of occurrences of this token in this string.
|
static boolean |
hasLength(String str)
Checks whether this string is not
null and not empty. |
static boolean |
hasText(String s)
Checks whether this string isn't
null and contains at least one non-blank character. |
static boolean |
isCharAnyOf(char c,
String chars)
Checks whether this characters matches any of these characters.
|
static String |
left(String str,
int count)
Returns the first n characters from this string, where n = count.
|
static String |
leftPad(String original,
int length,
char padChar) |
static String |
replace(String inString,
String oldPattern,
String newPattern)
Replace all occurences of a substring within a string with
another string.
|
static String |
replaceAll(String str,
String originalToken,
String replacementToken)
Replaces all occurrances of this originalToken in this string with this replacementToken.
|
static boolean |
startsAndEndsWith(String str,
String prefix,
String... suffixes)
Checks whether this strings both begins with this prefix and ends withs either of these suffixes.
|
static String[] |
tokenizeToStringArray(String str,
String delimiters)
Splits this string into an array using these delimiters.
|
static List<String> |
tokenizeToStringCollection(String str,
char delimiterChar,
char groupDelimiterChar)
Splits this string into a collection using this delimiter and this group delimiter.
|
static List<String> |
tokenizeToStringCollection(String str,
String delimiters)
Splits this string into a collection using these delimiters.
|
static String |
trimLeadingCharacter(String str,
char character)
Trim any leading occurrence of this character from the given String.
|
static String |
trimLeadingWhitespace(String str)
Trim leading whitespace from the given String.
|
static String |
trimLineBreak(String str)
Trim the trailing linebreak (if any) from this string.
|
static String |
trimOrLeftPad(String str,
int length,
char padChar)
Trims or pads this string, so it has this exact length.
|
static String |
trimOrPad(String str,
int length)
Trims or pads (with spaces) this string, so it has this exact length.
|
static String |
trimOrPad(String str,
int length,
char padChar)
Trims or pads this string, so it has this exact length.
|
static String |
trimTrailingWhitespace(String str)
Trim trailing whitespace from the given String.
|
static String |
wordWrap(String str,
int lineSize)
Wrap this string at the word boundary at or below lineSize characters.
|
static String |
wrap(String str,
int lineSize)
Wrap this string every lineSize characters.
|
public static String trimOrPad(String str, int length)
str - The string to adjust. null is treated as an empty string.length - The exact length to reach.public static String trimOrPad(String str, int length, char padChar)
str - The string to adjust. null is treated as an empty string.length - The exact length to reach.padChar - The padding character.public static String trimOrLeftPad(String str, int length, char padChar)
str - The string to adjust. null is treated as an empty string.length - The exact length to reach.padChar - The padding character.public static String collapseWhitespace(String str)
str - The string to analyse.public static String left(String str, int count)
str - The string to parse.count - The amount of characters to return.public static String replaceAll(String str, String originalToken, String replacementToken)
str - The string to process.originalToken - The token to replace.replacementToken - The replacement.public static boolean hasLength(String str)
null and not empty.str - The string to check.true if it has content, false if it is null or blank.public static String arrayToCommaDelimitedString(Object[] strings)
strings - The array to process.strings is empty. null if strings is null.public static String arrayToDelimitedString(String delimiter, Object[] strings)
delimiter - The delimiter to use.strings - The array to process.strings is empty. null if strings is null.public static boolean hasText(String s)
null and contains at least one non-blank character.s - The string to check.true if it has text, false if not.public static String[] tokenizeToStringArray(String str, String delimiters)
str - The string to split.delimiters - The delimiters to use.public static List<String> tokenizeToStringCollection(String str, String delimiters)
str - The string to split.delimiters - The delimiters to use.public static List<String> tokenizeToStringCollection(String str, char delimiterChar, char groupDelimiterChar)
str - The string to split.delimiterChar - The delimiter to use.groupDelimiterChar - The character to use to delimit groups.public static int countOccurrencesOf(String str, String token)
str - The string to analyse.token - The token to look for.public static String replace(String inString, String oldPattern, String newPattern)
inString - String to examineoldPattern - String to replacenewPattern - String to insertpublic static String collectionToCommaDelimitedString(Collection<?> collection)
toString() implementations.collection - the Collection to analysepublic static String collectionToDelimitedString(Collection<?> collection, String delimiter)
toString() implementations.collection - the Collection to analysedelimiter - The delimiter.public static String trimLeadingWhitespace(String str)
str - the String to checkCharacter.isWhitespace(char)public static String trimLeadingCharacter(String str, char character)
str - the String to check.character - The character to trim.Character.isWhitespace(char)public static String trimTrailingWhitespace(String str)
str - the String to checkCharacter.isWhitespace(char)public static boolean startsAndEndsWith(String str, String prefix, String... suffixes)
str - The string to check.prefix - The prefix.suffixes - The suffixes.true if it does, false if not.public static String trimLineBreak(String str)
str - The string.public static String wrap(String str, int lineSize)
str - The string to wrap.lineSize - The maximum size of each line.public static String wordWrap(String str, int lineSize)
str - The string to wrap.lineSize - The maximum size of each line.public static boolean isCharAnyOf(char c,
String chars)
c - The char to check.chars - The chars that should match.true if it does, false if not.Copyright © 2022. All rights reserved.