public final class StringUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY |
static String |
FOLDER_SEPARATOR |
Modifier and Type | Method and Description |
---|---|
static int |
count(CharSequence content,
CharSequence token)
Count the number of times that 'token' occurs within 'content'.
|
static int |
count(String s,
char c) |
static String |
createString(byte[] bytes,
String encoding)
Convert a byte[] into a String with a particular encoding.
|
static String |
createUtf8String(byte[] bytes)
Convert a byte[] into a UTF-8 String.
|
static String |
createUTF8String(byte[] bytes)
Convert a byte[] into a UTF-8 encoded String.
|
static int |
damerauLevenshteinDistance(CharSequence source,
CharSequence target)
Calculate the Damerau-Levenshtein Distance between two strings.
|
static byte[] |
decode(String s) |
static String |
encode(byte[] bytes)
Convert a byte array into a printable format containing a
String of hex digit characters (two per byte).
|
static boolean |
equals(CharSequence cs1,
CharSequence cs2)
Compares two CharSequences, returning
true if they represent
equal sequences of characters. |
static boolean |
equalsIgnoreCase(CharSequence cs1,
CharSequence cs2)
Compares two CharSequences, returning
true if they represent
equal sequences of characters, ignoring case. |
static boolean |
equalsIgnoreCaseWithTrim(String s1,
String s2) |
static boolean |
equalsWithTrim(String s1,
String s2) |
static byte[] |
getBytes(String s,
String encoding)
Convert a String into a byte[] with a particular encoding.
|
static String |
getRandomChar(Random random,
boolean upper) |
static String |
getRandomString(Random random,
int minLen,
int maxLen) |
static byte[] |
getUTF8Bytes(String s)
Convert a String into a byte[] encoded by UTF-8.
|
static boolean |
hasContent(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static int |
hashCodeIgnoreCase(String s)
Get the hashCode of a String, insensitive to case, without any new Strings
being created on the heap.
|
static boolean |
isEmpty(CharSequence cs)
Checks if a CharSequence is empty (""), null, or only whitespace.
|
static boolean |
isNotEmpty(CharSequence cs)
Checks if a CharSequence is not null, not empty (""), and not only whitespace.
|
static boolean |
isNotWhitespace(CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
|
static boolean |
isWhitespace(CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
|
static int |
lastIndexOf(String path,
char ch) |
static int |
length(CharSequence cs)
Gets a CharSequence length or
0 if the CharSequence is null . |
static int |
levenshteinDistance(CharSequence s,
CharSequence t)
The Levenshtein distance is a string metric for measuring the difference between two sequences.
|
static String |
trim(String str)
Removes control characters (char <= 32) from both
ends of this String, handling
null by returning
null . |
static String |
trimEmptyToDefault(String value,
String defaultValue)
Trims a string, If the string trims to empty then we return the default.
|
static int |
trimLength(String s) |
static String |
trimToEmpty(String value)
Trims a string, its null safe and null will return empty string here..
|
static String |
trimToNull(String value)
Trims a string, If the string trims to empty then we return null.
|
static String |
wildcardToRegexString(String wildcard)
Convert strings containing DOS-style '*' or '?' to a regex String.
|
public static final String FOLDER_SEPARATOR
public static final String EMPTY
public static boolean equals(CharSequence cs1, CharSequence cs2)
true
if they represent
equal sequences of characters.
null
s are handled without exceptions. Two null
references are considered to be equal. The comparison is case-sensitive.
cs1
- the first CharSequence, may be null
cs2
- the second CharSequence, may be null
true
if the CharSequences are equal (case-sensitive), or both null
equalsIgnoreCase(CharSequence, CharSequence)
public static boolean equalsIgnoreCase(CharSequence cs1, CharSequence cs2)
true
if they represent
equal sequences of characters, ignoring case.
null
s are handled without exceptions. Two null
references are considered equal. The comparison is case insensitive.
cs1
- the first CharSequence, may be null
cs2
- the second CharSequence, may be null
true
if the CharSequences are equal (case-insensitive), or both null
equals(CharSequence, CharSequence)
public static boolean isEmpty(CharSequence cs)
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is empty or nullpublic static boolean isNotWhitespace(CharSequence cs)
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is
not empty and not null and not whitespace onlypublic static boolean isWhitespace(CharSequence cs)
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is null, empty or whitespace onlypublic static boolean isNotEmpty(CharSequence cs)
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is not empty and not nullpublic static boolean hasContent(CharSequence cs)
cs
- the CharSequence to check, may be nulltrue
if the CharSequence is
not empty and not null and not whitespace onlypublic static int length(CharSequence cs)
0
if the CharSequence is null
.cs
- a CharSequence or null
0
if the CharSequence is null
.public static int trimLength(String s)
s
- a String or null
public static int lastIndexOf(String path, char ch)
public static byte[] decode(String s)
public static String encode(byte[] bytes)
bytes
- array representationpublic static int count(String s, char c)
public static int count(CharSequence content, CharSequence token)
public static String wildcardToRegexString(String wildcard)
public static int levenshteinDistance(CharSequence s, CharSequence t)
s
- String onet
- String twopublic static int damerauLevenshteinDistance(CharSequence source, CharSequence target)
source
- Source input stringtarget
- Target input stringpublic static String getRandomString(Random random, int minLen, int maxLen)
random
- Random instanceminLen
- minimum number of charactersmaxLen
- maximum number of characterspublic static byte[] getBytes(String s, String encoding)
s
- string to encode into bytesencoding
- encoding to usepublic static String createUtf8String(byte[] bytes)
bytes
- bytes to encode into a stringpublic static byte[] getUTF8Bytes(String s)
s
- string to encode into bytespublic static String createString(byte[] bytes, String encoding)
bytes
- bytes to encode into a stringencoding
- encoding to usepublic static String createUTF8String(byte[] bytes)
bytes
- bytes to encode into a stringpublic static int hashCodeIgnoreCase(String s)
s
- String inputpublic static String trim(String str)
null
by returning
null
.
The String is trimmed using String.trim()
.
Trim removes start and end characters <= 32.
str
- the String to be trimmed, may be nullnull
if null String inputpublic static String trimToEmpty(String value)
value
- string inputpublic static String trimToNull(String value)
value
- string inputpublic static String trimEmptyToDefault(String value, String defaultValue)
value
- string inputdefaultValue
- value to return on empty or nullCopyright © 2024. All rights reserved.