String class Methods in Java Part-III

java.lang.String

The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.

Some Methods of String class

regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)It tests if two string regions are equal. A substring of this String object is compared to a substring of the argument other.


repeat()It returns a string whose value is the concatenation of this string repeated count times.


replaceAll()It replaces each substring of this string that matches the given regular expression with the given replacement.


replace(char oldChar, char newChar) It returns a string resulting from replacing all occurrences of oldChar in this string with newChar.


replace(CharSequence target, CharSequence replacement)It replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.


replaceFirst()It replaces the first substring of this string that matches the given regular expression with the given replacement.


split(String regex)It splits this string around matches of the given regular expression.


split(String regex, int limit)It splits this string around matches of the given regular expression.


startsWith(String prefix)It tests if this string starts with the specified prefix.


startsWith(String prefix, int offset)It tests if the substring of this string beginning at the specified index starts with the specified prefix.


strip()It returns a string whose value is this string, with all leading and trailing white space removed.


stripIndent()It returns a string whose value is this string, with incidental white space removed from the beginning and end of every line.


stripLeading()It returns a string whose value is this string, with all leading white space removed.


stripTrailing()It returns a string whose value is this string, with all trailing white space removed.


subSequence() It returns a character sequence that is a subsequence of this sequence.


substring(int beginIndex)It returns a string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.


substring(int beginIndex, int endIndex)It returns a string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex -1.


toCharArray()It converts this string to a new character array.


toLowerCase()It converts all of the characters in this String to lower case using the rules of the default locale.


toLowerCase(Locale locale)It converts all of the characters in this String to lowercase using the rules of the given Locale.


Some more Methods of String Part - I


Some more Methods of String Part -II


Some more Methods of String Part - IV


No comments:

Post a Comment