TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to JAVA

Java toLowerCase, toUpperCase Examples

Use the toLowerCase and toUpperCase methods to modify the character casing in strings.
ToLowerCase. A string has uppercase letters. But we want just lowercase letters—the toLowerCase method is useful here. We call toLowerCase on an existing String object.Strings
With another method, toUpperCase we go from lower to uppercase. Only letters are affected by these methods. Spaces and digits are left alone.
An example. With the methods toUpperCase() and toLowerCase(), we change cases. The toUpperCase method affects only lowercase letters. And toLowerCase affects only uppercase ones.

Tip: Numbers, punctuation and whitespace are unaffected by these two methods. Sometimes, the methods will make no changes.

Info: The space character in the string "The Golden Bowl" is not changed. You cannot uppercase a space.

Java program that changes casing public class Program { public static void main(String[] args) { // A mixed-case string. String value1 = "The Golden Bowl"; // Change casing. String upper = value1.toUpperCase(); String lower = value1.toLowerCase(); // Print results. System.out.println(upper); System.out.println(lower); } } Output THE GOLDEN BOWL the golden bowl
Notes, performance. There is a possible performance gain in storing the result of toUpperCase and toLowerCase. A HashMap could be used. You can reduce string allocations this way.HashMap
A summary. As with other string manipulation methods, toUpperCase and toLowerCase do not modify an existing string. Instead they copy and return new strings.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf