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());
	}
}
Output: testingpool.com

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());
	}
}
Output:TESTINGPOOL.COM

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());
	}
}
Output: testingpool.com

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);
		}
	}
}
Output:TESTINGPOOL.COM
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. August 7, 2015

    […] char[] toCharArray() […]