public class StringUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
firstLower(String string)
Returns the string with the first character capitalized.
|
static String |
firstUpper(String string)
Returns the string with the first character capitalized.
|
static byte[] |
getAsciiBytes(String string)
Encodes the given String into a sequence of bytes using the Ascii character
set.
|
static byte[] |
getLatin1Bytes(String string)
Encodes the given String into a sequence of bytes using the Latin1 character
set.
|
static String |
htmlEscape(String str)
Returns the given
String according to the HTML 4.0 encoding rules. |
static String |
htmlUnescape(String str)
Returns the given
String decoded according to the HTML 4.0 decoding
rules. |
static boolean |
isNullOrEmpty(String string)
Returns
true if the given string is null or is the empty string. |
static String |
nullToEmpty(String string)
Returns the given string if it is non-null; the empty string otherwise.
|
static String |
repeat(String string,
int occurrences)
Returns the given string repeated the number of times requested.
|
static List<String> |
splitAndTrim(String stringToSplit)
Returns an list of trimmed token splitted with the split character ",".
|
static List<String> |
splitAndTrim(String stringToSplit,
String splitCharacter)
Returns an list of trimmed token splitted with the split character.
|
static String |
strip(String source,
char delimiter)
Strips a delimiter character from both ends of the source string.
|
static String |
strip(String source,
char delimiter,
boolean start,
boolean end)
Strips a delimiter character from a source string.
|
public static String firstLower(String string)
string - a string reference to checkpublic static String firstUpper(String string)
string - a string reference to checkpublic static byte[] getAsciiBytes(String string)
string - The string to encode.public static byte[] getLatin1Bytes(String string)
string - The string to encode.public static String htmlEscape(String str)
String according to the HTML 4.0 encoding rules.public static String htmlUnescape(String str)
String decoded according to the HTML 4.0 decoding
rules.public static boolean isNullOrEmpty(String string)
true if the given string is null or is the empty string.
Consider normalizing your string references with nullToEmpty(java.lang.String). If you
do, you can use String.isEmpty() instead of this method, and you
won't need special null-safe forms of methods like String.toUpperCase(java.util.Locale)
either.string - a string reference to checktrue if the string is null or is the empty stringpublic static String nullToEmpty(String string)
string - the string to test and possibly returnstring itself if it is non-null; "" if it is nullpublic static String repeat(String string, int occurrences)
string - String to be repeated.occurrences - Number of times to repeat the string.public static List<String> splitAndTrim(String stringToSplit)
stringToSplit - The String to split.public static List<String> splitAndTrim(String stringToSplit, String splitCharacter)
stringToSplit - The String to split.splitCharacter - The split Character.public static String strip(String source, char delimiter)
source - The source string to strip.delimiter - The character to remove.public static String strip(String source, char delimiter, boolean start, boolean end)
source - The source string to strip.delimiter - The character to remove.start - Indicates if start of source should be stripped.end - Indicates if end of source should be stripped.Copyright © 2005–2025. All rights reserved.