CodesJava

Easy learning with example program codes

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.

Syntax:

public String toUpperCase()

Example:

CaseChangeExample.java

/**
 * This program is used to show the use of 
 * toUpperCase and toLowerCase methods.
 * @author codesjava
 */
class TestString{
	String str = "Jai";
 
	/**
	 * This method is used to show the use of toUpperCase() method.
	 * @author codesjava
	 */
	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 codesjava
	 */
	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.

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status