String class Methods in Java Part-II

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


getBytes(String charsetName): It encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.


hashCode(): It returns a hash code for this string. 


indent(): It adjusts the indentation of each line of this string based on the value of n and normalizes line termination characters.


indexOf(int ch): It returns the index within this string of the first occurrence of the specified character. 


indexOf(int ch, int fromIndex): It returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. 


indexOf(String str): It returns the index within this string of the first occurrence of the specified substring.


indexOf(String str, int fromIndex): It returns the index within this string of the first occurrence of the specified substring, starting at the specified index.


intern(): It returns a canonical representation for the string object.

isBlank(): It returns true if the string is empty or contains only white space code points, otherwise false.


isEmpty(): It returns true if, and only if, length() is 0.

String.join(): It returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.


String.join(CharSequence delimiter, Iterable<? extends CharSequence> elements): It returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.


lastIndexOf(int ch):  It returns the index within this string of the last occurrence of the specified character. 


lastIndexOf(int ch, int fromIndex): It returns the index within this string of the last occurrence of the specified character.


lastIndexOf(String str): It returns the index within this string of the last occurrence of the specified substring.


lastIndexOf(String str, int fromIndex): It returns the index within this string of the last occurrence of the specified substring.


length(): It returns the length of this string.


matches(): It tells whether or not this string matches the given regular expression.


offsetByCodePoints():It returns the index within this String that is offset from the given index by codePointOffset code points.


regionMatches(int toffset, String other, int ooffset, int len): It tests if two string regions are equal.


Some more Methods of String Part - I


Some more Methods of String Part - III


Some more Methods of String Part -IV


No comments:

Post a Comment