public final class StringUtils extends Object
This class contains methods for handling CharSequence and StringBuilder instances, including:
CharSequences for content equality.CharSequence starts or ends with a specific substring.StringBuilder.NumberFormatException with custom messages.Note: This class is not meant to be instantiated and therefore has a private constructor.
| Modifier and Type | Method and Description |
|---|---|
static boolean |
endsWith(@NotNull CharSequence source,
@NotNull String endsWith)
Checks if the given
CharSequence ends with the specified string, in a case-insensitive way. |
static boolean |
equalsCaseIgnore(@Nullable CharSequence s,
@NotNull CharSequence cs)
Compares two
CharSequences for equality ignoring case considerations. |
static byte[] |
extractBytes(@NotNull String s) |
static byte[] |
extractBytes(@NotNull StringBuilder sb) |
static char[] |
extractChars(@NotNull String s) |
static char[] |
extractChars(StringBuilder sb) |
static @Nullable String |
firstLowerCase(@Nullable String str) |
static byte |
getStringCoder(@NotNull String str) |
static byte |
getStringCoder(@NotNull StringBuilder str) |
static boolean |
isEqual(@Nullable CharSequence s,
@Nullable CharSequence cs)
Compares two
CharSequences for content equality. |
static boolean |
isEqual(@Nullable StringBuilder s,
@Nullable CharSequence cs)
Compares a
StringBuilder and a CharSequence for content equality. |
static @NotNull String |
newString(char[] chars) |
static @NotNull String |
newStringFromBytes(byte[] bytes) |
static double |
parseDouble(@NotNull CharSequence in) |
static int |
parseInt(CharSequence s,
int radix) |
static long |
parseLong(CharSequence s,
int radix) |
static void |
reverse(StringBuilder text,
int start)
Reverses a portion of the content of a
StringBuilder in place, from the given start index to the end. |
static void |
set(@NotNull StringBuilder sb,
CharSequence cs)
Sets the content of a
StringBuilder to the content of the given CharSequence. |
static void |
setCount(@NotNull StringBuilder sb,
int count) |
static void |
setLength(@NotNull StringBuilder sb,
int length)
Sets the length of a
StringBuilder without altering its content. |
static boolean |
startsWith(@NotNull CharSequence source,
@NotNull String startsWith)
Checks if the given
CharSequence starts with the specified string. |
static @Nullable String |
toString(@Nullable Object o)
Returns the string representation of the specified object.
|
static @Nullable String |
toTitleCase(@Nullable String name)
Converts the given string to title case.
|
public static boolean isEqual(@Nullable
@Nullable StringBuilder s,
@Nullable
@Nullable CharSequence cs)
StringBuilder and a CharSequence for content equality.s - the StringBuilder to be compared.cs - the CharSequence to be compared.true if both character sequences are equal, false otherwise.public static void setLength(@NotNull
@NotNull StringBuilder sb,
int length)
StringBuilder without altering its content.
This operation has performance benefits compared to StringBuilder.setLength(int).sb - the StringBuilder whose length needs to be set.length - the new length.AssertionError - if there is an IllegalAccessException or IllegalArgumentException.public static void set(@NotNull
@NotNull StringBuilder sb,
CharSequence cs)
StringBuilder to the content of the given CharSequence.sb - the StringBuilder to be modified.cs - the CharSequence whose content will be set in the StringBuilder.public static boolean endsWith(@NotNull
@NotNull CharSequence source,
@NotNull
@NotNull String endsWith)
CharSequence ends with the specified string, in a case-insensitive way.source - the CharSequence to be checked.endsWith - the string to check if the CharSequence ends with.true if the CharSequence ends with the specified string, false otherwise.public static boolean startsWith(@NotNull
@NotNull CharSequence source,
@NotNull
@NotNull String startsWith)
CharSequence starts with the specified string.source - the CharSequence to be checked.startsWith - the string to check if the CharSequence starts with.true if the CharSequence starts with the specified string, false otherwise.public static boolean isEqual(@Nullable
@Nullable CharSequence s,
@Nullable
@Nullable CharSequence cs)
CharSequences for content equality.s - the first CharSequence to be compared.cs - the second CharSequence to be compared.true if both character sequences are equal, false otherwise.public static char[] extractChars(StringBuilder sb)
public static boolean equalsCaseIgnore(@Nullable
@Nullable CharSequence s,
@NotNull
@NotNull CharSequence cs)
CharSequences for equality ignoring case considerations.s - the first CharSequence to be compared.cs - the second CharSequence to be compared.true if the CharSequences are equal irrespective of case, false otherwise.@Nullable public static @Nullable String toString(@Nullable @Nullable Object o)
o - the object whose string representation is to be returned.public static byte getStringCoder(@NotNull
@NotNull String str)
public static byte getStringCoder(@NotNull
@NotNull StringBuilder str)
public static byte[] extractBytes(@NotNull
@NotNull StringBuilder sb)
public static char[] extractChars(@NotNull
@NotNull String s)
public static byte[] extractBytes(@NotNull
@NotNull String s)
public static void setCount(@NotNull
@NotNull StringBuilder sb,
int count)
@NotNull public static @NotNull String newString(char[] chars)
@NotNull public static @NotNull String newStringFromBytes(byte[] bytes)
@Nullable public static @Nullable String firstLowerCase(@Nullable @Nullable String str)
public static double parseDouble(@NotNull
@NotNull CharSequence in)
@Nullable public static @Nullable String toTitleCase(@Nullable @Nullable String name)
name - the input string to be converted.public static void reverse(StringBuilder text, int start)
StringBuilder in place, from the given start index to the end.text - the StringBuilder whose content needs to be partially reversed.start - the index from which to start the reverse operation.public static int parseInt(CharSequence s, int radix) throws NumberFormatException
NumberFormatExceptionpublic static long parseLong(CharSequence s, int radix) throws NumberFormatException
NumberFormatExceptionCopyright © 2024. All rights reserved.