String in Java
String: A Java string is a sequence of characters that exist as an object of the class java. lang.
Here is the list of important methods available in the java string class:
Ø startsWith(): It checks if the string starts with the given prefix. If yes then return true else false.
Ø endsWith(): It checks if the string ends with the given suffix. If yes then return true else false.
Ø substring(int begin index) : It returns the substring of the string. The substring starts with the character at the specified index.
Ø substring(Int begin index , int end index) : Returns the substring. The substring starts with the character at begin index and ends with the character at end index.
Ø toLowerCase() : It converts all the characters of the string into lower case(Small Letters).
Ø toUpperCase() : It converts all the characters of the string into upper case(Capital Letter).
Ø indexOf() : It returns the position of the first occurrence of the specified character or string in a specified string.
Ø lastIndexOf() : It return the last index of the given character.
Ø isEmpty() : This method return true if the given string has 0 length.
Ø length() : It returns the length of a string.
Ø equals() : Compare both the strings and return true if both matches else false.
Ø equalsIgnoreCase() : It works the same as equals but it does a case insensitive comparison.
Ø charAt() : It returns the character at the specified index number.
Ø trim() : It returns the substring after eliminating leading and trailing white space from the original string.
Ø concat() : Concatenates the specified string at the end of the string.
Ø contains() : It checks whether a string contains the specified sequence of a character value. If yes then it returns true else false.
Ø replace() : it returns a string after replacing all old characters with a new character.
Comments
Post a Comment