Convert a character to lower case. - Java java.lang

Java examples for java.lang:String Case

Introduction

The following code shows how to <p>Convert a character to lower case. .

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        char character = 'a';
        System.out.println(charToLowerCase(character));
    }/*w  w w .  j a  va  2 s.c o m*/

    /**
     * <p>Convert a character to lower case. If the character is already in lower case
     * then no change is performed.</p>
     * @param character character to modify
     * @return lower case character.
     */
    public static char charToLowerCase(final char character) {
        char newCharacter = character;
        int firstHexChar = (int) character;

        /*
         * If this is a upper case, convert to lower case.
         */
        if (firstHexChar > 0x40 && firstHexChar < 0x5B) {
            newCharacter = (char) (firstHexChar + 0x20);
        }

        return newCharacter;
    }
}

Related Tutorials