The java.lang.String class provides a lot of methods to work on string. By the help of these methods,
We can perform operations on string such as trimming, concatenating, converting, comparing, replacing strings etc.
1) to Lowercase (): Converts all of the characters in this String to lower case.
Syntax: s1.toLowerCase()
Example: String s="Sachin";
System.out.println(s.toLowerCase());
Output: sachin
2)to Uppercase():Converts all of the characters in this String to
upper case
Syntax: s1.toUpperCase()
Example:
String s="Sachin";
System.out.println(s.toUpperCase());
Output: SACHIN
3) trim (): Returns a copy of the string, with leading and trailing
whitespace omitted.
Syntax: s1.trim()
Example:
String s=" Sachin ";
System.out.println(s.trim());
Output:Sachin
4) replace ():Returns a new string resulting from replacing all
occurrences of old Char in this string with new Char.
Syntax: s1.replace(‘x’,’y’)
Example:
String s1="Java is a programming language. Java is a platform.";
String s2=s1.replace("Java","Kava"); //replaces all occurrences
of "Java" to "Kava"
System.out.println(s2);
Output: Kava is a programming language. Kava is a platform.