Java String Methods

Java has a lot of String methods that allow us to work with strings. In this reference page, you will find all the string methods available in Java. For example, if you need to find the length of a string, use the length() method.

Java String split()

Splits the string at the specified string (regex)

Java String compareTo()

Compares two strings in the dictionary order

Java String compareToIgnoreCase()

Compares two strings ignoring case differences

Java String length()

Returns the length of the string

Java String replace()

Replace all matching characters/text in the string

Java String replaceAll()

Replace all substrings matching the regex pattern

Java String substring()

Returns a substring from the given string

Java String equals()

Compares two strings

Java String equalsIgnoreCase()

Compares two strings ignoring case differences

Java String contains()

Checks whether the string contains a substring

Java String indexOf()

Returns the index of the character/substring

Java String trim()

Removes any leading and trailing whitespace

Java String charAt()

Returns the character at the given index

Java String toLowerCase()

Converts characters in the string to lower case

Java String concat()

Concatenates two strings and returns it

Java String valueOf()

Returns the string representation of a value

Java String matches()

checks whether the string matches the given regex

Java String startsWith()

Checks if the string begins with the given string

Java String endsWith()

Checks if the string ends with the given string

Java String isEmpty()

Checks whether a string is empty or not

Java String intern()

Returns a canonical representation of the string

Java String getBytes()

Encodes the string into a sequences of bytes

Java String contentEquals()

Checks whether the string is equal to charSequence

Java String hashCode()

Returns a hash code for the string

Java String join()

Joins the given strings using the delimiter

Java String replaceFirst()

Replace the first matching substring

Java String subSequence()

Returns a subsequence from the string

Java String toCharArray()

Converts the string to a char array

Java String format()

Returns a formatted string