public final class Strings extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
concatenate(Object... objects) |
static boolean |
contains(String str,
char searchChar)
Checks if String contains a search character, handling
null. |
static boolean |
contains(String str,
String searchStr)
Checks if String contains a search String, handling
null. |
static boolean |
containsAny(String str,
char... chars)
Checks if the String contains any character in the given set of characters.
|
static boolean |
containsAny(String str,
String searchChars)
Checks if the String contains any character in the given set of characters.
|
static boolean |
endsWith(String str,
String suffix)
Check if a String ends with a specified suffix.
Two null references are considered to be equal. |
static boolean |
isEmpty(String str)
Checks if a String is empty ("") or null or blank (" ").
isEmpty(null) = true |
static boolean |
isNotEmpty(String str)
Checks if a String is NOT empty ("") or null or blank (" ").
isEmpty(null) = false |
static int |
length(String str)
Returns the length of this string.
|
static boolean |
like(String str,
String pattern)
Checks if the String is matched using given Pattern.
Syntax: |
static String |
lowerCase(String str)
Converts a String to lower case
A null input String returns null. |
static String |
removeEnd(String str,
String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
|
static String |
removeStart(String str,
String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
|
static String |
replace(String str,
String searchString,
String replacement)
Replaces all occurrences of a String within another String
A null reference passed to this method is a no-op. |
static String |
replace(String str,
String searchString,
String replacement,
int max)
Replaces a String with another String inside a larger String, for the first max values of the search String.
A null reference passed to this method is a no-op. |
static boolean |
startsWith(String str,
String prefix)
Check if a String starts with a specified prefix.
Two null references are considered to be equal. |
static String |
substr(String str,
int pos,
int length) |
static String |
substring(String str,
int beginIndex)
Gets a substring from the specified String
A negative start position can be used to start n characters from the end of the String. A null String will return null. |
static String |
substring(String str,
int beginIndex,
int endIndex)
Gets a substring from the specified String
A negative start position can be used to start/end n characters from the end of the String. |
static Double |
toDouble(String str) |
static Integer |
toInteger(String str) |
static Number |
toNumber(String str) |
static String |
toString(Object obj) |
static String |
trim(String str)
Returns a string whose value is this string, with any leading and trailing whitespace removed.
|
static String |
upperCase(String str)
Converts a String to upper case
A null input String returns null.
upperCase(null) = null |
public static boolean contains(String str, String searchStr)
Checks if String contains a search String, handling null. This method uses
String.indexOf(String).
A null String will return false.
contains(null, *) = false
contains(*, null) = false
contains("", "") = true
contains("abc", "") = true
contains("abc", "a") = true
contains("abc", "z") = false
str - the String to check, may be nullsearchStr - the String to find, may be nullnull string inputpublic static boolean contains(String str, char searchChar)
Checks if String contains a search character, handling null. This method uses
String.indexOf(int).
A null or empty ("") String will return false.
contains(null, *) = false
contains("", *) = false
contains("abc", 'a') = true
contains("abc", 'z') = false
str - the String to check, may be nullsearchChar - the character to findnull string inputpublic static boolean containsAny(String str, char... chars)
Checks if the String contains any character in the given set of characters.
A null String will return false. A null or zero length search array will
return false.
containsAny(null, *) = false
containsAny("", *) = false
containsAny(*, null) = false
containsAny(*, []) = false
containsAny("zzabyycdxx",['z','a']) = true
containsAny("zzabyycdxx",['b','y']) = true
containsAny("aba", ['z']) = false
str - the String to check, may be nullchars - the chars to search for, may be nulltrue if any of the chars are found, false if no match or null inputpublic static boolean containsAny(String str, String searchChars)
Checks if the String contains any character in the given set of characters.
A null String will return false. A null search string will return
false.
containsAny(null, *) = false
containsAny("", *) = false
containsAny(*, null) = false
containsAny(*, "") = false
containsAny("zzabyycdxx", "za") = true
containsAny("zzabyycdxx", "by") = true
containsAny("aba","z") = false
str - the String to check, may be nullsearchChars - the chars to search for, may be nulltrue if any of the chars are found, false if no match or null inputpublic static boolean isEmpty(String str)
isEmpty(null) = true
isEmpty("") = true
isEmpty(" ") = true
isEmpty("bob") = false
isEmpty(" bob ") = false
str - the String to check, may be nullpublic static boolean isNotEmpty(String str)
isEmpty(null) = false
isEmpty("") = false
isEmpty(" ") = false
isEmpty("bob") = true
isEmpty(" bob ") = true
str - the String to check, may be nullisEmpty(String)public static int length(String str)
public static String trim(String str)
public static boolean startsWith(String str, String prefix)
startsWith(null, null) = true
startsWith(null, "abc") = false
startsWith("abcdef", null) = false
startsWith("abcdef", "abc") = true
startsWith("ABCDEF", "abc") = false
str - the String to check, may be nullprefix - the prefix to find, may be nullpublic static boolean endsWith(String str, String suffix)
endsWith(null, null) = true
endsWith(null, "def") = false
endsWith("abcdef", null) = false
endsWith("abcdef", "def") = true
endsWith("ABCDEF", "def") = false
endsWith("ABCDEF", "cde") = false
str - the String to check, may be nullsuffix - the suffix to find, may be nullpublic static String substring(String str, int beginIndex)
str - the String to get the substring from, may be nullbeginIndex - the position to start from, negative means count back from the end of the String by this many
characterspublic static String substring(String str, int beginIndex, int endIndex)
substring(null, *, *) = null
substring("", * , *) = "";
substring("abc", 0, 2) = "ab"
substring("abc", 2, 0) = ""
substring("abc", 2, 4) = "c"
substring("abc", 4, 6) = ""
substring("abc", 2, 2) = ""
substring("abc", -2, -1) = "b"
substring("abc", -4, 2) = "ab"
str - the String to get the substring from, may be nullbeginIndex - the position to start from, negative means count back from the end of the String by this many
charactersendIndex - the position to end at (exclusive), negative means count back from the end of the String by this
many characterspublic static String removeStart(String str, String remove)
removeStart(null, *) = null
removeStart("", *) = ""
removeStart(*, null) = *
removeStart("www.domain.com", "www.") = "domain.com"
removeStart("domain.com", "www.") = "domain.com"
removeStart("www.domain.com", "domain") = "www.domain.com"
removeStart("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullpublic static String removeEnd(String str, String remove)
removeEnd(null, *) = null
removeEnd("", *) = ""
removeEnd(*, null) = *
removeEnd("www.domain.com", ".com.") = "www.domain.com"
removeEnd("www.domain.com", ".com") = "www.domain"
removeEnd("www.domain.com", "domain") = "www.domain.com"
removeEnd("abc", "") = "abc"
str - the source String to search, may be nullremove - the String to search for and remove, may be nullpublic static String lowerCase(String str)
lowerCase(null) = null
lowerCase("") = ""
lowerCase("aBc") = "abc"
str - the String to lower case, may be nullpublic static String upperCase(String str)
upperCase(null) = null
upperCase("") = ""
upperCase("aBc") = "ABC"
str - the String to upper case, may be nullpublic static String replace(String str, String searchString, String replacement)
replace(null, *, *) = null
replace("", *, *) = ""
replace("any", null, *) = "any"
replace("any", *, null) = "any"
replace("any", "", *) = "any"
replace("aba", "a", null) = "aba"
replace("aba", "a", "") = "b"
replace("aba", "a", "z") = "zbz"
str - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace it with, may be nullpublic static String replace(String str, String searchString, String replacement, int max)
replace(null, *, *, *) = null
replace("", *, *, *) = ""
replace("any", null, *, *) = "any"
replace("any", *, null, *) = "any"
replace("any", "", *, *) = "any"
replace("any", *, *, 0) = "any"
replace("abaa", "a", null, -1) = "abaa"
replace("abaa", "a", "", -1) = "b"
replace("abaa", "a", "z", 0) = "abaa"
replace("abaa", "a", "z", 1) = "zbaa"
replace("abaa", "a", "z", 2) = "zbza"
replace("abaa", "a", "z", -1) = "zbzz"
str - text to search and replace in, may be nullsearchString - the String to search for, may be nullreplacement - the String to replace it with, may be nullmax - maximum number of values to replace, or -1 if no maximumpublic static boolean like(String str, String pattern)
# - matches any single digit ? - matches any single character * - matches any character 0 or more times @ - matches any single alphabetic character [charlist] - matches any single character incharlist[!charlist]- matches any single character not incharlistX+ - matches @{code X} one or more times
like(null, "") = true
like("", "#") = false
like("9", "#") = true
like("a", "?") = true
like("a", "@") = true
like("1a23", "*") = true
like("foo@bar.com", "?+\@?+\.?+") = true
like("+38(099) 123-12-12", "+##(###) ###-##-##") = true
str - any Stringpattern - patterntrue if the String matches given patternCopyright © 2004–2019 OpenL Tablets. All rights reserved.