Class Strings
java.lang.Object
net.buildtheearth.terraminusminus.util.Strings
String related utility functions.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountMatches(@Nullable CharSequence haystack, char needle) Counts the number of times a chars appears in a string.static intcountMatches(@Nullable CharSequence haystack, @Nullable CharSequence needle) Counts the number of times a substring appears in a string.static booleanisNullOrEmpty(@Nullable String string) Tests whether astringis null or empty.static @NonNull String[]split(@Nullable CharSequence str, char delimiter) Splits a string into a string array using a given delimiter.
-
Field Details
-
EMPTY_STRING_ARRAY
-
-
Method Details
-
isNullOrEmpty
Tests whether astringis null or empty.- Parameters:
string- a string to test- Returns:
- true if the string is either null or the empty string, false otherwise
-
countMatches
public static int countMatches(@Nullable @Nullable CharSequence haystack, @Nullable @Nullable CharSequence needle) Counts the number of times a substring appears in a string. Occurrences of the substring overlapping each other count as one.- Parameters:
haystack- the string to search inneedle- the substring to search- Returns:
- the number of occurrences of the substring in the string, or 0 if either is null
-
countMatches
Counts the number of times a chars appears in a string.- Parameters:
haystack- the string to search inneedle- the char to search- Returns:
- the number of occurrences of the substring in the string, or 0 if the string is null
-
split
@NonNull public static @NonNull String[] split(@Nullable @Nullable CharSequence str, char delimiter) Splits a string into a string array using a given delimiter. The delimiter is not included in the members of the resulting array. A null string returns an empty array.- Parameters:
str- the string to splitdelimiter- the delimiter to split the string with- Returns:
- an array where each entry is a section of the origin string that was delimited by the given delimiter
-