A comprehensive reference guide to the most commonly used methods in Java's String class with practical examples and usage tips.
Returns the index within this string of the first occurrence of the specified substring.
Returns the index within this string of the last occurrence of the specified substring.
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to endIndex - 1.
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Compares this string to the specified object. The result is true if the argument is not null and is a String object that represents the same sequence of characters.
Compares two strings lexicographically. Returns a negative integer, zero, or a positive integer as this string is less than, equal to, or greater than the specified string.
Converts all of the characters in this String to lower case using the rules of the default locale.
Converts all of the characters in this String to upper case using the rules of the default locale.
Returns the length of this string. The length is equal to the number of Unicode code units in the string.
Returns a string whose value is this string, with any leading and trailing whitespace removed.
Returns true if and only if this string contains the specified sequence of char values.
Concatenates the specified string to the end of this string.
Returns the string representation of the various data types. This is a static method.
Returns true if, and only if, length() is 0.