Convert String from working capital missive of the alphabet to lowercase inwards Java
Sometime nosotros take to convert String from lowercase to working capital missive of the alphabet or from working capital missive of the alphabet to lowercase e.g. earlier printing or storing into database etc. String bird inwards Java provides or therefore utility method to perform this instance conversion. You tin role toUpperCase() to convert whatsoever lower instance String to working capital missive of the alphabet in addition to toLowerCase() to convert whatsoever working capital missive of the alphabet String to lowercase. Key affair to retrieve acre using toUpperCase() and toLowerCase() is that they render a unlike String rather than modifying same String because String is immutable inwards Java. So if yous role onetime String, assuming it has been converted into working capital missive of the alphabet or lowercase therefore yous may exercise but, instead merely shop novel String returned yesteryear these methods into same variable which is concur to shop onetime String. Once i time again getting familiar amongst primal classes similar java.lang.String is really of import for Java programmer every bit nosotros oftentimes take to Split String, replace String or take white infinite from String etc. String provides several convenient method to exercise this without using external library. In this Java tutorial nosotros volition likewise run into consummate Java computer program to convert String to lowercase in addition to working capital missive of the alphabet inwards Java.
Java computer program to convert String to lowercase in addition to Uppercase inwards Java
Here is my consummate code instance of performing this conversion. We accept used measure toUpperCase() and toLowerCase() method to convert String from lowercase to uppercase in addition to after from working capital missive of the alphabet to lowercase inwards Java.
How to convert a String from lowercase to upper instance in addition to vice-versa
How to convert a String from lowercase to upper instance in addition to vice-versa
package test;
/**
* Java computer program to convert String from lowercase to uppercase and
* working capital missive of the alphabet to lowercase inwards Java. We tin role toUpperCase() to convert whatsoever String
* to upper instance inwards Java in addition to toLowerCase() method of String bird to convert any
* String to lower instance inwards Java.
*
* @author http://java67.blogspot.com
*/
public class StringCaseConverter {
public static void main(String args[]) {
//example of converting String to Upper instance inwards Java
//input String which contains words inwards lowercase
String strInLowerCase = "this string is inwards lowercase";
System.out.println("String earlier converting to Uppercase");
System.out.println("input : " + strInLowerCase);
// converting lowercase String to working capital missive of the alphabet inwards Java
String strInUpperCase = strInLowerCase.toUpperCase(); //toUpperCase render lowercase of String
System.out.println("String after converting to Uppercase");
System.out.println("output : " + strInLowerCase);
//Now let's run into an instance of converting String to lower case
String upper = "THIS IS UPPER CASE STRING";
String lower = upper.toLowerCase(); //toLowerCase() render lowercase of String
System.out.println("input String earlier converting to LowerCase : " + upper);
System.out.println("output String after converting to LowerCase : " + lower);
}
}
Output:
String earlier converting to Uppercase
input : this string is inwards lowercase
String after converting to Uppercase
output : this string is inwards lowercase
input String earlier converting to LowerCase : THIS IS UPPER CASE STRING
output String after converting to LowerCase : this is upper case string
/**
* Java computer program to convert String from lowercase to uppercase and
* working capital missive of the alphabet to lowercase inwards Java. We tin role toUpperCase() to convert whatsoever String
* to upper instance inwards Java in addition to toLowerCase() method of String bird to convert any
* String to lower instance inwards Java.
*
* @author http://java67.blogspot.com
*/
public class StringCaseConverter {
public static void main(String args[]) {
//example of converting String to Upper instance inwards Java
//input String which contains words inwards lowercase
String strInLowerCase = "this string is inwards lowercase";
System.out.println("String earlier converting to Uppercase");
System.out.println("input : " + strInLowerCase);
// converting lowercase String to working capital missive of the alphabet inwards Java
String strInUpperCase = strInLowerCase.toUpperCase(); //toUpperCase render lowercase of String
System.out.println("String after converting to Uppercase");
System.out.println("output : " + strInLowerCase);
//Now let's run into an instance of converting String to lower case
String upper = "THIS IS UPPER CASE STRING";
String lower = upper.toLowerCase(); //toLowerCase() render lowercase of String
System.out.println("input String earlier converting to LowerCase : " + upper);
System.out.println("output String after converting to LowerCase : " + lower);
}
}
Output:
String earlier converting to Uppercase
input : this string is inwards lowercase
String after converting to Uppercase
output : this string is inwards lowercase
input String earlier converting to LowerCase : THIS IS UPPER CASE STRING
output String after converting to LowerCase : this is upper case string
That's all on how to convert lowercase String to Uppercase inwards Java. We accept likewise seen instance of converting Uppercase string to lowercase using method toLowerCase() inwards Java.
Further Learning
Data Structures in addition to Algorithms: Deep Dive Using Java
Why char array is ameliorate than String for storing password
No comments:
Post a Comment