Tuesday, December 11, 2012
How to convert String from lowercase to uppercase and lowercase in Java
Convert String from uppercase to lowercase in Java
Sometime we need to convert String from lowercase to uppercase or from uppercase to lowercase e.g. before printing or storing into database etc. String class in Java provides some utility method to perform this case conversion. You can use toUpperCase() to convert any lower case String to uppercase and toLowerCase() to convert any uppercase String to lowercase. Key thing to remember while using toUpperCase() and toLowerCase() is that they return a different String rather than modifying same String because String is immutable in Java. So if you use old String, assuming it has been converted into uppercase or lowercase then you may create but, instead just store new String returned by these methods into same variable which is hold to store old String. Once again getting familiar with key classes like java.lang.String is very important for Java programmer as we often need to Split String, replace String or remove white space from String etc. String provides several convenient method to do this without using external library. In this Java tutorial we will also see complete Java program to convert String to lowercase and uppercase in Java.
Here is my complete code example of performing this conversion. We have used standard toUpperCase() and toLowerCase() method to convert String from lowercase to uppercase and subsequently from uppercase to lowercase in Java.
That's all on how to convert lowercase String to Uppercase in Java. We have also seen example of converting Uppercase string to lowercase using method toLowerCase() in Java.
Other String related articles you may find useful