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.