String Class Method
String Class Method
codePointAt() Returns the Unicode of the character at the specified index int
codePointBefore() Returns the Unicode of the character before the specified index int
contentEquals() Checks whether a string contains the exact same sequence of boolean
characters of the specified CharSequence or StringBuffer
copyValueOf() Returns a String that represents the characters of the character String
array
endsWith() Checks whether a string ends with the specified character(s) boolean
equals() Compares two strings. Returns true if the strings are equal, and boolean
false if not
format() Returns a formatted string using the specified locale, format String
string, and arguments
indexOf() Returns the position of the first found occurrence of specified int
characters in a string
intern() Returns the canonical representation for the string object String
lastIndexOf() Returns the position of the last found occurrence of specified int
characters in a string
matches() Searches a string for a match against a regular expression, and boolean
returns the matches
offsetByCodePoints() Returns the index within this String that is offset from the given int
index by codePointOffset code points
replace() Searches a string for a specified value, and returns a new string String
where the specified values are replaced
replaceAll() Replaces each substring of this string that matches the given String
regular expression with the given replacement
replaceFirst() Replaces the first occurrence of a substring that matches the String
given regular expression with the given replacement
substring() Returns a new string which is the substring of a specified string String
class Main {
public static void main(String[] args) {
{
String s= "Welcome to Java Programming";
// or String s= new String ("Welcome to Java Programming ");
// Return the substring from the ith index character to end of string
System.out.println("Substring " + s.substring(3));
// Returns the index within the string of the first occurrence of the specified
string,
// starting at the specified index.
System.out.println("Index of a = " +
s4.indexOf('a',1));
//If ASCII difference is zero then the two strings are similar
// Converting cases
String w1 = " Hello!! Good Morning";
System.out.println("Changing to lower Case " +
w1.toLowerCase());
// Converting cases
System.out.println("Changing to UPPER Case " +
w1.toUpperCase());
// Replacing characters
String str1 = "I love Java";
System.out.println("Original String " + str1);
String str2 = str1.replace('J' ,'j') ;
System.out.println("Replaced J with j -> " + str2);
}
}