Java Char Lower Case toLowerCase(char c)

Here you can find the source of toLowerCase(char c)

Description

Do an ASCII only lower case conversion.

License

Academic Free License

Declaration

public static char toLowerCase(char c) 

Method Source Code

//package com.java2s;
// Licensed under the Academic Free License version 3.0

public class Main {
    /**//from   w w w.j  a va  2s .c  o  m
     * Do an ASCII only lower case conversion.  Case conversion
     * with Locale can result in unexpected side effects.
     */
    public static char toLowerCase(char c) {
        if ('A' <= c && c <= 'Z')
            return (char) (c | 0x20);
        else
            return c;
    }

    /**
     * Do an ASCII only lower case conversion.  Case conversion
     * with Locale can result in unexpected side effects.
     */
    public static String toLowerCase(String s) {
        // first scan to see if string isn't already ok
        int len = s.length();
        int first = -1;
        for (int i = 0; i < len; ++i) {
            char a = s.charAt(i);
            char b = toLowerCase(a);
            if (a != b) {
                first = i;
                break;
            }
        }
        if (first == -1)
            return s;

        // allocate new char buf and copy up to first change
        char[] buf = new char[len];
        s.getChars(0, first, buf, 0);

        // change remainder of string
        for (int i = first; i < len; ++i)
            buf[i] = toLowerCase(s.charAt(i));

        return new String(buf);
    }
}

Related

  1. toLowerCase(char b)
  2. toLowerCase(char c)
  3. toLowerCase(char c)
  4. toLowerCase(char ch)
  5. toLowerCase(char ch)
  6. toLowerCase(char[] chars)
  7. toLowerCase(char[] cs)