< Prev
Next >



String Methods




Some methods of String class

In the table below, we have given a short preview about some important methods of String class. You may click on the name of method to get a detailed description with an example.

Methods Description
length()
This method gives us the total length of a String i.e. total number of characters that make a String.

charAt()
This method gives us a character present at a particular index in a String.

concat()
This method appends one String at the end of another String

toUpperCase()
This method returns a String with all the lowercase characters in it converted to uppercase.

toLowerCase()
This method returns a String with all the uppercase characters in it converted to lowercase.

trim()
This method trims/removes all the leading and trailing whitespace characters in a String.

substring()
This method returns a part of a String i.e substring.

startsWith()
This method returns a substring that starts at an index we specify in this method and it ends at the end of the String.

endsWith()
This method returns a substring that starts at base index of String and it ends at the index we specify in this method.

indexOf(char ch)
This method returns us the index of the first occurrence of a String in a String.

lastIndexOf()
This method returns us the index of the last occurrence of a particular character in a String.

replace()
This method replaces all the occurrences of a particular character with a new character in the String.

equals()
This method checks for the equality of values in the two String objects.

equalsIgnoreCase()
This method checks for the equality of values in the two String objects, ignoring the case(lowercase/uppercase) in which character are present in a String.

toString()
This method is used when we need String representation of the value of an object.




Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter




< Prev
Next >
< Immutable String
toUpperCase() method >
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2