Java String Lower Case toLowerCase(final String s)

Here you can find the source of toLowerCase(final String s)

Description

Retrieves an all-lowercase version of the provided string.

License

Open Source License

Parameter

Parameter Description
s The string for which to retrieve the lowercase version.

Return

An all-lowercase version of the provided string.

Declaration

public static String toLowerCase(final String s) 

Method Source Code

//package com.java2s;
/*//from w  w  w  .  j  a va 2s.c om
 * Copyright 2011-2015 UnboundID Corp.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (GPLv2 only)
 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 */

public class Main {
    /**
     * Retrieves an all-lowercase version of the provided string.
     *
     * @param  s  The string for which to retrieve the lowercase version.
     *
     * @return  An all-lowercase version of the provided string.
     */
    public static String toLowerCase(final String s) {
        if (s == null) {
            return null;
        }

        final int length = s.length();
        final char[] charArray = s.toCharArray();
        for (int i = 0; i < length; i++) {
            switch (charArray[i]) {
            case 'A':
                charArray[i] = 'a';
                break;
            case 'B':
                charArray[i] = 'b';
                break;
            case 'C':
                charArray[i] = 'c';
                break;
            case 'D':
                charArray[i] = 'd';
                break;
            case 'E':
                charArray[i] = 'e';
                break;
            case 'F':
                charArray[i] = 'f';
                break;
            case 'G':
                charArray[i] = 'g';
                break;
            case 'H':
                charArray[i] = 'h';
                break;
            case 'I':
                charArray[i] = 'i';
                break;
            case 'J':
                charArray[i] = 'j';
                break;
            case 'K':
                charArray[i] = 'k';
                break;
            case 'L':
                charArray[i] = 'l';
                break;
            case 'M':
                charArray[i] = 'm';
                break;
            case 'N':
                charArray[i] = 'n';
                break;
            case 'O':
                charArray[i] = 'o';
                break;
            case 'P':
                charArray[i] = 'p';
                break;
            case 'Q':
                charArray[i] = 'q';
                break;
            case 'R':
                charArray[i] = 'r';
                break;
            case 'S':
                charArray[i] = 's';
                break;
            case 'T':
                charArray[i] = 't';
                break;
            case 'U':
                charArray[i] = 'u';
                break;
            case 'V':
                charArray[i] = 'v';
                break;
            case 'W':
                charArray[i] = 'w';
                break;
            case 'X':
                charArray[i] = 'x';
                break;
            case 'Y':
                charArray[i] = 'y';
                break;
            case 'Z':
                charArray[i] = 'z';
                break;
            default:
                if (charArray[i] > 0x7F) {
                    return s.toLowerCase();
                }
                break;
            }
        }

        return new String(charArray);
    }
}

Related

  1. toLowerCase(Enum aEnum)
  2. toLowerCase(final byte b)
  3. toLowerCase(final String s)
  4. toLowerCase(final String s)
  5. toLowerCase(final String s)
  6. toLowerCase(final String str)
  7. toLowerCase(final String[] strings)
  8. toLowerCase(final StringBuilder src)
  9. toLowercase(int codePoint)