• August 28, 2014
  • Core Java
  • Comments Off on toLowerCase() and toUpperCase() String functions in java

toLowerCase() and toUpperCase() String functions in java

toLowerCase(): Converts all of the characters in this String to lower case.

Syntax: public String toLowerCase().

toUpperCase(): Converts all of the characters in this String to upper case.

Synatx: public String toUpperCase().

Example:

CaseChangeExample.java

/**
 * This program is used to show the use of 
 * toUpperCase and toLowerCase methods.
 * @author javawithease
 */
class TestString{
	String str = "Jai";
 
	/**
	 * This method is used to show the use of toUpperCase() method.
	 * @author javawithease
	 */
	public void upperCase(){
		//will convert all characters in upper case.
		System.out.println(str.toUpperCase());
	}
 
	/**
	 * This method is used to show the use of toLowerCase() method.
	 * @author javawithease
	 */
	public void lowerCase(){
		//will convert all characters in lower case.
		System.out.println(str.toLowerCase());
	}
}
 
public class CaseChangeExample {
	public static void main(String args[]){
		//creating TestString object
		TestString obj = new TestString();
 
		//method call
		obj.upperCase();
		obj.lowerCase();
	}
}

Output:

JAI
jai

Download this example.
 
Next Topic: intern() String functions in java with example.
Previous Topic: indexOf(String str) and lastIndexOf(String str) String functions in java.

Related Topics:

String handling in java with example.
String Comparison in java with example.
String concatenation in java with example.
Substring in java with example.
How to write Immutable class in java with example.
toString() method in java with example.
Commonly used methods of String Class with example.
charAt(int index) String function in java with example.
startsWith(String prefix) and endsWith(String suffix) String functions in java.
indexOf(String str) and lastIndexOf(String str) String functions in java.
toLowerCase() and toUpperCase() String functions in java.
intern() String functions in java with example.
length() String functions in java with example.
trim() String functions in java with example.

 


Comments are closed.