String methods – toString,toUppercase,toLowercase,toChararray
In this post, we will discuss about the string methods toString,toUppercase,toLowercase,toChararray.
Let’s see them one by one with examples.
String toString():
This method returns itself i.e. a same string.
public class StringMethodsEx { public static void main(String[] args) { String val1 = "testingpool.com"; System.out.println(val1.toString()); } }
String toUpperCase():
This methods converts all characters of a string into uppercase and returns a string.
public class StringMethodsEx { public static void main(String[] args) { String val1 = "testingpool.com"; System.out.println(val1.toUpperCase()); } }
String toLowerCase():
It converts all characters of a string into lowercase and returns string.
public class StringMethodsEx { public static void main(String[] args) { String val1 = "TESTINGPOOL.COM"; // STRING IN UPPERCASE System.out.println(val1.toLowerCase()); } }
char[] toCharArray():
This method converts a string into a new character array.
The length of the array will be same as length of the string.In the below example, it will result in the same string.
public class StringMethodsEx { public static void main(String[] args) { String val1 = "TESTINGPOOL.COM"; char[] a = val1.toCharArray(); for(char c : a){ System.out.print(c); } } }
1 Response
[…] char[] toCharArray() […]