Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
String methods - toString,toUppercase,toLowercase,toChararray - Testingpool

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() […]