banner



How To Make Java Change Entries To All Caps

Char to Majuscule/Lowercase in Coffee

  1. Catechumen a Grapheme to Upper-case letter/Lowercase Using the toUpperCase()/toLowerCase() Method
  2. Convert a Character to Capital letter/Lowercase Using Binary Operations and Hexadecimal
  3. Catechumen a Character to Majuscule and to Lowercase Using capitalize()/lowerCase From com.apache.commons

This tutorial introduces methods to convert a character to a lowercase/uppercase grapheme. Nosotros take four methods that we will come across with examples beneath.

Convert a Character to Uppercase/Lowercase Using the toUpperCase()/toLowerCase() Method

Character is a wrapper class for char and provides several methods to manipulate the grapheme like toUpperCase() and toLowerCase(). Though these methods cannot handle all the Unicode characters, they tin can handle the mutual alphabets.

Nosotros have 2 char variables, char1 has a lowercase character while char2 take an uppercase character. To convert char1 to an uppercase graphic symbol, we phone call the toUpperCase() static method from the Character grade and pass char1 as an argument. The same goes to convert char2 to lowercase; we call the toLowerCase() method.

              public class CharUpperLowerCase {     public static void main(String[] args) {         char char1, char2;          char1 = 'a';         char2 = 'B';          char char1UpperCase = Character.toUpperCase(char1);         char char2LowerCase = Character.toLowerCase(char2);          System.out.println(char1UpperCase);         Organisation.out.println(char2LowerCase);      } }                          

Output:

              A b                          

Convert a Grapheme to Capital/Lowercase Using Binary Operations and Hexadecimal

As every character has an ASCII value and a binary representation, we tin can perform binary operations. We use the hexadecimal 0x5f whose binary representation is 1011111 and 0x20 representing 0100000 in binary.

char1 has the character a and its binary value is 01100001, nosotros append & the symbol representing binary AND performance and 0x5f to the character. As we know that 0x5f has the binary value of 1011111 and when nosotros perform the AND performance that is between 01100001 AND 1011111 we get the value 01000001 that is the binary representation of uppercase A.

char2 contains the majuscule grapheme B, and its binary code is 01000010. We append the | symbol equal to the OR binary performance and 0x20 having the binary value of 0100000. At present 01000010 OR 0100000 volition be performed, and the outcome volition be 01100010 that is the aforementioned as the lowercase character b.

Notice that equally we use the char type to hold the characters, the binary values are converted into their representing characters without whatever casting.

              public class CharUpperLowerCase {     public static void master(String[] args) {         char char1, char2;          char1 = 'a' & 0x5f;         char2 = 'B' | 0x20;          System.out.println(char1);         System.out.println(char2);              } }                          

Output:

              A b                          

In this example, we apply the StringUtils form present in Apache Eatables Library. Beginning, we include the library in our project using the following maven dependency.

              <dependency>     <groupId>org.apache.commons</groupId>     <artifactId>eatables-lang3</artifactId>     <version>3.eleven</version> </dependency>                          

StringUtils equally the name indicates, provides utility methods to manipulate strings. Nosotros take two strings with a unmarried character in each. string1 has a lowercase a. nosotros use StringUtils.capitalize() and pass string1 as the argument to catechumen it to capital. string2 has an uppercase B. We can use StringUtils.lowerCase() and laissez passer string2 every bit an argument to convert information technology to lowercase.

Nosotros get the result in the string type, merely our goal is to go the value in char data type, so, we use charAt(0) to become the single and only grapheme in both the Strings as a char.

              import org.apache.commons.lang3.StringUtils;  public class CharUpperLowerCase {     public static void main(String[] args) {         char char1, char2;          String string1 = "a";         Cord string2 = "B";          String string1UpperCase = StringUtils.capitalize(string1);         String string2LowerCase = StringUtils.lowerCase(string2);          char1 = string1UpperCase.charAt(0);         char2 = string2LowerCase.charAt(0);         Organisation.out.println(char1);         Organisation.out.println(char2);      } }                          

Output:

              A b                          

Write for united states

DelftStack articles are written by software geeks similar you lot. If you also would like to contribute to DelftStack past writing paid articles, you can check the write for the states folio.

Related Article - Coffee Char

  • Convert Int to Char in Coffee
  • Char vs String in Java
  • Initialize Char in Java
  • Stand for Empty Char in Java
  • Ezoic

    Source: https://www.delftstack.com/howto/java/char-to-uppercase-lowercase-java/

    Posted by: farrellsymeave.blogspot.com

    0 Response to "How To Make Java Change Entries To All Caps"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel