Share on Google+Share on Google+

Java : String Case Conversion

Advertisement
In this section we will discuss how to convert a String from one case into another case.

Java : String Case Conversion

In this section we will discuss how to convert a String from one case into another case.

Upper to Lower case Conversion :

By using toLowerCase() method you can convert any upper case char/String into lower case char/String.

Lower to Upper case Conversion :

By using toUpperCase() method you can convert any lower case char/String into upper case char/String.

Example :

class StringCaseConversion {
public static void main(String[] args) {
String uStr = "Hello ROSEINDIA";
String lStr = "hello world";
String uCaseStr, lCaseStr;

// Convert into lower case
lCaseStr = uStr.toLowerCase();
System.out.println("String in lower case: " + lCaseStr);

// Convert into upper case
uCaseStr = lStr.toUpperCase();
System.out.println("String in upper case: " + uCaseStr);
}
}

Description : This example shows conversion of String from one case to another case. 'uStr' String type variable containing upper case string value and 'lStr' containing lower case String value. We have another two String type variable uCaseStr and lCaseStrto for result. Next we are going to convert uStr into lower case by using toLowerCase() method and result is stored in lCaseStr as  - lCaseStr = uStr.toLowerCase();   In the same way we can convert 'lStr' ito upper case by writing code - uCaseStr = lStr.toUpperCase();

Output :

String in lower case: hello roseindia
String in upper case: HELLO WORLD

Advertisements

Posted on: November 22, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.