String Methods in Java
One of the most vital parts of Java is Strings. As a Java programmer, one of your main tools
for storing and processing data is the String class.
What makes Strings so powerful in Java? The answer to that will be methods of String class. The java.lang.String provides a
bunch of
useful methods which can be used to perform various operations on a sequence of character
values.
Let us list out all the methods which falls under the String class. You can just click
on any method and read about it in detail with explained example codes.
String Methods
- – Returns the character value at the specified index. The index value
should be between 0 to length()-1, both inclusive.
- – Returns the Unicode value of the character at the specified
index.
- – Returns the Unicode value of the character before the
specified index.
- – Returns the number of Unicode point
values in the specified range of the String.
- – Compares two strings in dictionary order, also known
as lexicographically.
- – Concatenates the specified string to the end of this
string.
- – Returns true or false after checking if the specified
sequence of characters is present in the string or not.
- – Compares this string to the specified character
sequence.
- – Returns a string that represents the character sequence in
the array specified.
- – Checks whether the string ends with the specified characters
or not.
- – Returns true or false after comparing this string to the
specified string.
- – Returns the index within the string of the first occurrence of the
specified character/substring.
- – Returns the length of the specified string.
- - Returns the index within the string of the last occurrence of the
specified character/substring.
- – Returns a new string by replacing all the
occurrences of oldChar with newChar.
- – Returns true of false after checking if the string starts
with the specified prefix.
- – Returns a new string that is a substring of this string.
- – Converts all the characters of the string to lower
case and upper case respectively.
Summary
We have seen the overview of String methods in Java. Make sure to check each one of these methods in detail and get a fair idea about how it works. Some of the methods listed above have sub-categories depending upon the parameters specified.