Java String Methods
Last Updated : 11 Feb 2026
In Java, the String class represents a sequence of characters. It is a fundamental part of the language that is used extensively for storing and manipulating text data. It has many built-in methods that help us to do string manipulations like, cutting parts of a sentence, joining two pieces of text, changing the format, checking if two texts are the same or replacing one word with another.
Java String Class Methods
The java.lang.String class provides many useful methods to perform operations on sequence of char values.
| Method | Description |
|---|---|
| char charAt(int index) | It returns char value for the particular index |
| int length() | It returns string length |
| static String format(String format, Object... args) | It returns a formatted string. |
| static String format(Locale l, String format, Object... args) | It returns formatted string with given locale. |
| String substring(int beginIndex) | It returns substring for given begin index. |
| String substring(int beginIndex, int endIndex) | It returns substring for given begin index and end index. |
| boolean contains(CharSequence s) | It returns true or false after matching the sequence of char value. |
| static String join(CharSequence delimiter, CharSequence... elements) | It returns a joined string. |
| static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) | It returns a joined string. |
| boolean equals(Object another) | It checks the equality of string with the given object. |
| boolean isEmpty() | It checks if string is empty. |
| String concat(String str) | It concatenates the specified string. |
| String replace(char old, char new) | It replaces all occurrences of the specified char value. |
| String replace(CharSequence old, CharSequence new) | It replaces all occurrences of the specified CharSequence. |
| static String equalsIgnoreCase(String another) | It compares another string. It doesn't check case. |
| String[] split(String regex) | It returns a split string-matching regex. |
| String[] split(String regex, int limit) | It returns a split string-matching regex and limit. |
| String intern() | It returns an interned string. |
| int indexOf(int ch) | It returns the specified char value index. |
| int indexOf(int ch, int fromIndex) | It returns the specified char value index starting with given index. |
| int indexOf(String substring) | It returns the specified substring index. |
| int indexOf(String substring, int fromIndex) | It returns the specified substring index starting with given index. |
| String toLowerCase() | It returns a string in lowercase. |
| String toLowerCase(Locale l) | It returns a string in lowercase using specified locale. |
| String toUpperCase() | It returns a string in uppercase. |
| String toUpperCase(Locale l) | It returns a string in uppercase using specified locale. |
| String trim() | It removes beginning and ending spaces of this string. |
| static String valueOf(int value) | It converts given type into string. It is an overloaded method. |
Java String Methods Example
Java String.toUpperCase() and String.toLowerCase() Method
The String.toUpperCase() method converts the String into uppercase and the String.toLowerCase() method converts the String into lowercase.
Output:
COMPUTER computer Computer
Java String.trim() Method
The method eliminates white spaces before and after the String.
Output:
Java String.startsWith() and String.endsWith() Method
The String.startsWith() method checks whether the String starts with the letters passed as arguments and String.endsWith() method checks whether the String ends with the letters passed as arguments.
Output:
Java String.charAt() Method
The String.charAt() method returns a character at specified index.
Output:
Java String.length() Method
The String.length() method returns length of the specified String.
Output:
Java String.intern() Method
A pool of strings, initially empty, is maintained privately by the class String.
When the intern method is invoked, if the pool already contains a String equal to this String object as determined by the equals(Object) method, then the String from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
Output:
Java String.valueOf() Method
The String.valueOf() method coverts given type such as int, long, float, double, boolean, char and char array into String.
Output:
Java String.replace() Method
The String.replace() method replaces all occurrence of first sequence of character with second sequence of character.
Output:
Kava is a programming language. Kava is a platform. Kava is an Island.