Puts all chars in the StringBuilder in lower case. - Java java.lang

Java examples for java.lang:StringBuilder

Description

Puts all chars in the StringBuilder in lower case.

Demo Code

/*  Copyright 2011 Alexander Bunkenburg alex@inspiracio.com

    This file is part of atom.jar.//from w w  w. ja  v  a2  s . c o  m

    atom.jar is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    atom.jar 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 atom.jar.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        StringBuilder builder = new StringBuilder();
        toLowerCase(builder);
    }

    /** Puts all chars in the builder in lower case.
     * Does not allocate Strings, does not change the size of the
     * builder.
     * @param builder to be put into lower case */
    public static void toLowerCase(StringBuilder builder) {
        final int N = builder.length();
        for (int i = 0; i < N; i++) {
            char c = builder.charAt(i);
            if (Character.isUpperCase(c)) {
                c = Character.toLowerCase(c);
                builder.setCharAt(i, c);
            }
        }
    }
}

Related Tutorials